initWithStyle: reuseIdentifier: 与 registerClass: forCellReuseIdentifier: 冲突问题 cell.detailTextLabel.

来源:互联网 发布:洗面奶推荐知乎 编辑:程序博客网 时间:2024/06/15 02:20

ios 在用tableView布局的时候,遇到了这样一个情况:

cell.detailTextLabel.text 不显示;无论怎么调试,都不显示

代码展示:

[self.tableViewregisterClass:[UITableViewCellclass] forCellReuseIdentifier:@"cell"];


UITableViewCell *cell = [tableViewdequeueReusableCellWithIdentifier:@"cell"];

    if (cell ==nil) {

        cell = [[UITableViewCellalloc] initWithStyle:UITableViewCellStyleValue1reuseIdentifier:@"cell"];

    }

    cell.detailTextLabel.text =@"未设置";

注册cell与cell属性设置出现了冲突,在if判断处,由于注册cell,导致 cell!= nil,所以initWithStyle:UITableViewCellStyleValue1,不会被执行,而cell的属性则为默认值:UITableViewCellStyleDefault,副标题不显示。为了结局这一问题,我用了一个比较笨的方法,将控制器改为继承自UITableViewControllView,这样去掉了注册cell这一关,直接创建cell,cell的属性设置就有效了。方法比较笨,有更好的解决办法留言私聊,谢谢!
0 0
原创粉丝点击