zoukankan      html  css  js  c++  java
  • iOS UI基础07

    • 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];
             }
  • 相关阅读:
    解决Ant design vue的Layout布局,左右布局侧边栏无效不显示问题
    寻找写代码感觉(十二)之 封装分页请求参数和返回参数
    解决关于interceptor拦截器跨域AccessControlAllowOrigin报错问题
    解决Vue3引入自定义组件报错Cannot find module ‘xxx‘ or its corresponding type declarations问题
    解决antD中关于table组件中报这样的警告warning.js?2149:7 Warning: [antdv: Each record in table should have a unique `key` prop,or set `rowKey` to an unique primary key.]问题
    Centos 更改MySQL5.7数据库目录位置
    解决typescript:error TS2531: Object is possibly 'null'.问题
    解决npm WARN Local package.json exists, but node_modules missing, did you mean to install?问题
    弱监督学习文章略读记录
    弱监督学习最新文章略读
  • 原文地址:https://www.cnblogs.com/liujiaoxian/p/4706015.html
Copyright © 2011-2022 走看看