UITableViewCell正在分配但未显示

时间:2012-12-25 16:45:26

标签: ios uitableview

非常奇怪的问题。我有一个UITableViewController与故事板的自定义单元格。由于某种原因,单元格没有显示在我的TableView中。我放了一些断点和一些日志消息,我可以告诉它获取数据,我可以看到单元格有一个内存地址所以它不是零。我只是不知道还有什么可以验证。

UPDATE由于某种原因,单元格的隐藏属性被设置为YES所以我添加了cell.hidden = NO并且它仍然没有出现。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier;
if(indexPath.section == 0) {
    CellIdentifier = @"HeaderCell";
} else {
    CellIdentifier = @"ConnectedGoalCell";
}

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

if(indexPath.section == 0) {
 //Section 0 Formatting.....displays OK
} else {
 //This is the cell that doesn't appear in the tableView

    UILabel * nameLabel = (UILabel*)[cell viewWithTag:10];
    UILabel * dateLabel = (UILabel*)[cell viewWithTag:11];

    NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
    formatter.timeZone = [NSTimeZone defaultTimeZone];
    [formatter setDateFormat:@"MM/dd/yyyy"];
    Goal * goal = [connectedGoals objectAtIndex:indexPath.row];
    nameLabel.text = goal.name;
    dateLabel.text = [formatter stringFromDate:goal.goal_date];
    //Log said that cell HIDDEN was YES. Changed to no here but still no effect
     //<UITableViewCell: 0xa288e30; frame = (0 389; 320 44); autoresize = W; layer = <CALayer: 0xa292a80>
    cell.hidden = NO;
    NSLog(@"CELL TYPE : %@ AT %@", indexPath, CellIdentifier);
    //Logs::  CELL TYPE : <NSIndexPath 0xc3917d0> 2 indexes [1, 0] AT ConnectedGoalCell

    NSLog(@"%@", cell);
    //Logs::  CELL TYPE : <UITableViewCell: 0xc195ba0; frame = (0 389; 320 44); hidden = YES; autoresize = W; layer = <CALayer: 0xc171620>

}

return cell;
}

3 个答案:

答案 0 :(得分:1)

结束我必须在我的故事板中创建一个新的TableViewController并再次设置我的自定义视图,一切正常现在我的一个自定义单元格中有大约20个按钮,幸运的是我能够粘贴它们而不必繁琐地重新设置 - 再次创建它们。非常奇怪的错误,但它现在正在工作!

答案 1 :(得分:0)

阅读您的日志

  

CELL TYPE:UITableViewCell:0xc195ba0; frame =(0 389; 320 44); 隐藏= YES; autoresize = W;

我不知道它隐藏的原因,但显然不应该这样。

cell.hidden = NO;

答案 2 :(得分:0)

您正在使用dequeueReusableCellWithIdentifier:forIndexPath:方法(而不是dequeueReusableCellWithIdentifier:方法,然后检查nil),这意味着您必须调用其中一个register*:forCellReuseIdentifier,说,viewDidLoad。来自文档:

  

重要说明:您必须使用以下命令注册类或nib文件   registerNib:forCellReuseIdentifier:或   调用此方法之前的registerClass:forCellReuseIdentifier:方法   方法