首页 > 学院 > 开发设计 > 正文

iOSUI基础07

2019-11-14 18:34:52
字体:
来源:转载
供稿:网友
  • TableView

    • 属性

         // 设置每一行cell的高度   @PRoperty (nonatomic)CGFloat rowHeight;   // 设置每一组头部的高度   @property (nonatomic)CGFloat sectionHeaderHeight;   // 设置分割线颜色   @property (nonatomic, retain) UIColor *separatorColor   // 设置表头控件   @property (nonatomic, retain) UIView *tableHeaderView;   // 设置表尾控件   @property (nonatomic, retain) UIView *tableFooterView;   // 2.组头组尾的高   self.tableView.sectionHeaderHeight = 55;   self.tableView.sectionFooterHeight = 22;   // 3.设置整个tablView的头部/尾部视图   self.tableView.tableHeaderView = [[UISwitch alloc] init];   self.tableView.tableFooterView = [UIButton buttonWithType:UIButtonTypeInfoDark];   // 4.设置我们分割线颜色(clearColor相当于取消系统分割线)   //self.tableView.separatorColor = [UIColor clearColor];  // 5.设置分割线样式   self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    • 数据源方法
        //cell有多少组-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView //告诉tableView第section组有多少行-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section//告诉tableView每一行显示什么内容(tableView的每一行都是UITableViewCell)-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath //告诉tableView第section组的头部标题文字-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section // 告诉tableView第section组的尾部标题文字-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section//返回每一组的索引标题- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView // 返回每个cell的高度 -(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath//删除数据- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath;//
    • 代理方法
       // 只要实现了这个方法,左滑出现按钮的功能就有了(一旦左滑出现了N个按钮,tableView就进入了编辑模式, tableView.editing = YES)         -(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath     //左滑cell时出现什么按钮       -(NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath    {      UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"关注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {        NSLog(@"点击了关注");        // 收回左滑出现的按钮(退出编辑模式)        tableView.editing = NO;    }];    UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {        [self.wineArray removeObjectAtIndex:indexPath.row];        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];    }];    return @[action1, action0];}    //代理方法获取点滴选中行,行号    - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath;    //允许编辑选中行    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath;
  • UITableViewCell

    • 属性:
      //设置cell右边的指示样式//accessoryView的优先级 > accessoryType//cell.accessoryView = [[UISwitch alloc] init];@property (nonatomic) UITableViewCellAccessoryType    accessoryType;// default is UITableViewCellAccessoryNone. use to set standard type
    • Cell 创建

      • 注册创建

        [self.tableview registerClass:[UITableViewCell class] forCellReuseIdentifier:ID];//注册后可以直接从缓存中找创建好的UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
      • 非注册创建

        • 先从缓存持中查找

           UITableViewCell *cell=[tableView dequeueReusableCellWithIdentifier:ID];
        • 查不到在创建

           if (nil==cell) {cell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:ID]; }

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表