UITableView不能显示detailtext

起因很简单,就是跟着教程做,熟悉UITableView的使用,看到书上说cell有textLabel , imageview ,还有一个detailTextLabel,前面两个知道,但是后一个有点好奇,于是就试了一下,结果编译倒是没有问题,但是没有显示detailTextLabel,于是google吧,终于在这里 找到了答案。其实就是在初始化cell使用的参数不合适,换成下面代码中的

initWithStyle:UITableViewCellStyleSubtitle

就可以了。不行你试试。原谅我的low,为了认识什么叫header和footer我把它们也给打印出来了。


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    //UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:<#@"reuseIdentifier"#> forIndexPath:indexPath];


    static NSString *simpleTableIdentifier = @"AnimalsCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
    if(cell == nil)
    {
        //cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:simpleTableIdentifier];

    }
    cell.textLabel.text = [animals objectAtIndex:indexPath.row];
    cell.detailTextLabel.text = @"this is a detail text";

    /*
    //if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"8.0"))
    {
        if ([cell.detailTextLabel.text length]==0)
        {
            cell.detailTextLabel.text = @"detail ";
        }
        NSLog(@"detail.lenght=%lu",[cell.detailTextLabel.text length]);
        [cell layoutSubviews];
    }
    */
    
    // Configure the cell...
    
    return cell;
}


补充说一下,其他类型的 style 在下面的官方链接中有具体的介绍 点击打开链接


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值