tableView 属性设置

发布时间:2020-07-09 14:24:58 作者:缘起愿落
来源:网络 阅读:323

    指定tableView的数据源
    tableView.dataSource = self;

    指定tableview代理
    tableView.delegate = self;
        

    配置索引值的颜色
    tableView.sectionIndexColor = [UIColor lightGreenColor];


     设置tableview的headerView(最上面显示的视图)
    UILabel * phoneLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0, 320, 40)];
    phoneLabel.textColor = [UIColor lightGreenColor];
    phoneLabel.text = @"888888";
    phoneLabel.textAlignment = NSTextAlignmentCenter;
    tableView.tableHeaderView = phoneLabel;
    RELEASE_SAFE(phoneLabel);

        

    设置分割线的样式
        tableView.separatorStyle = UITableViewCellSeparatorStyleSingleLineEtched;
   

    设置分割线颜色
    tableView.separatorColor = [UIColor purpleColor];


    self.navigationItem.title = @"lanou";

   
      设置 tableView行高
    tableView.rowHeight = 70;


      获取文件路径
    NSString * path = [[NSBundle mainBundle] pathForResource:@"Student" ofType:@"plist"]


      根据文件路径初始化一个OC中字典对象
    NSDictionary * dic = [NSDictionary dictionaryWithContentsOfFile:path];
   


    设置行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
        偶数的cell 高度为100 ,奇数的cell为50
    if (indexPath.row %2 ) {
        return 100;
    }
    return 50;
}



    设置tableview右边的索引值(用来快速定位分区,方便查找), 要喝每个分区的title 对应上
    - (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
    {
        return self.titles;
    }
    

    设置分区尾显示的文字
    - (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section
    {
       return nil;
    }
  

     设置每个分区头显示的文字
    - (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
    {
        return self.titles[section];
    }

    返回tableView的分区个数   --- 1
    - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
    {
        return [self.names count];
    }

    设置tableview 的行数 (每个分组的行数)     ------ 2
    - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
    {
     先获取key        key =  self.titles[section]
    key获取对应数组    NSArray * value   = self.names[key]
     求数组个数         [value count]
   NSLog(@"3  %ld",(long)section);
    return 1000; //[self.names[self.titles[section]] count];
    }


 用来创建cell 每一行都要对应一个cell    ----- 3
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
     UITableViewCellStyleDefault,    只有textLabel
     UITableViewCellStyleValue1,    textLabel 在左   detailLabel 在右
     UITableViewCellStyleValue2,    textLabel 在右   detailLabel 在左
     UITableViewCellStyleSubtitle  textLabel 在上   detailLabel 在下
     
     
    
     UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil];
    cell.textLabel.text = self.names[indexPath.row]; //不分组
    
     分组
    获取key
     获取value
    取出元素
    
     cell.textLabel.text = self.names[self.titles[indexPath.section]][indexPath.row];
    
    cell.textLabel.text = self.names[indexPath.section][indexPath.row];
     return [cell autorelease]; ////////////////////////
   
     cell.textLabel.text = [NSString stringWithFormat:@"%d",indexPath.row];
    return cell;
    

推荐阅读:
  1. Swift中tableView怎么用
  2. iOS 提高tableView 性能的优化

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

数据源 属性设置 ev

上一篇:在Windows 10上安装Docker Desktop并启用Kubernetes

下一篇:74react_todolist2

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》