资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

tableView属性设置-创新互联

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

    指定tableview代理
   tableView.delegate = self;

成都创新互联技术团队10余年来致力于为客户提供成都网站设计、成都网站制作、品牌网站制作成都营销网站建设、搜索引擎SEO优化等服务。经过多年发展,公司拥有经验丰富的技术团队,先后服务、推广了成百上千家网站,包括各类中小企业、企事单位、高校等机构单位。

    配置索引值的颜色
   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;

另外有需要云服务器可以了解下创新互联scvps.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。


网站题目:tableView属性设置-创新互联
文章网址:http://cdkjz.cn/article/dpddhd.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

业务热线:400-028-6601 / 大客户专线   成都:13518219792   座机:028-86922220