首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >detailtextlabel设置为空

detailtextlabel设置为空
EN

Stack Overflow用户
提问于 2013-06-14 08:37:07
回答 1查看 735关注 0票数 0

我有带有style = UITableViewCellStyleValue1UITableViewCell单元格(在我的项目中使用的所有其他view controllers中都使用这种样式)。根据其他SO帖子的建议,我已经仔细检查了我的故事板中的cell identifiers。尽管如此,我仍然将detailTextLabel设置为零。我还有什么地方做错了吗?我观察到单元格总是被重用,也就是分配的if语句从来没有执行过。那么,如何获得UITableViewCell对象的样式来验证重用的单元格是否遵循相同的样式呢?

代码语言:javascript
运行
复制
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath     *)indexPath
{
    static NSString *CellIdentifier = @"CellForDevice";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1  reuseIdentifier:CellIdentifier];
     }
     NSLog(@"reuse ID : %@",cell.reuseIdentifier);
     // Configure the cell...
     NSArray* row = [self.listOfItems objectAtIndex:indexPath.row];
     NSString* str = [row objectAtIndex:0];
     NSString* status = [row objectAtIndex:1];
     cell.textLabel.text = str;

     if(cell.detailTextLabel == nil) 
        NSLog(@"detailTextLabel nil");//didn't expect this would execute

     cell.detailTextLabel.text = status;
     cell.detailTextLabel.backgroundColor = [UIColor greenColor];
     NSLog(@"status %@ ",status);
     return cell;
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-06-14 08:56:45

如果将单元格定义为情节提要文件中表格视图的原型单元格,则dequeueReusableCellWithIdentifier始终会根据需要实例化情节提要文件中的单元格。特别是,dequeueReusableCellWithIdentifier从不返回nil

因此,您应该检查原型单元格的属性,并且可以从代码中删除if (cell == nil)部件。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17099412

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档