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