2

很奇怪的问题。我有 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;
}
4

3 回答 3

1

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

于 2012-12-27T15:56:42.830 回答
0

您正在使用该dequeueReusableCellWithIdentifier:forIndexPath:方法(与该dequeueReusableCellWithIdentifier:方法相反,然后检查nil),这意味着您必须调用其中之一register*:forCellReuseIdentifier,例如viewDidLoad. 从文档:

重要提示:在调用此方法之前,您必须使用registerNib:forCellReuseIdentifier:or 方法注册类或 nib 文件 。registerClass:forCellReuseIdentifier:

于 2012-12-25T17:49:00.423 回答
0

阅读您的日志

单元格类型:UITableViewCell:0xc195ba0;帧 = (0 389; 320 44); 隐藏=是;自动调整大小 = W;

我不知道为什么要隐藏它,但显然不应该。

cell.hidden = NO;
于 2012-12-25T17:08:03.620 回答