我有一个让我发疯的问题。我认为这很容易解决,但我无法弄清楚。我做了一个简单的表格视图,它有两个数组的单元格。一个用于单元格中的正文,另一个用于单元格中的字幕。但问题是当我使用字幕样式制作单元格时,当我运行应用程序时看不到它们。这是我的代码:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if ( cell == nil){
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
}
cell.textLabel.text = [hop objectAtIndex:indexPath.row];
cell.detailTextLabel.text = [hop2 objectAtIndex:indexPath.row];
return cell;
}
当我调试时,我意识到当程序到达 if 块时,它不会进入块。这意味着"细胞"在那一刻不是零。问题是为什么会发生这种情况,我该如何解决这个问题?您的所有帮助将不胜感激。
我假设你使用的是iOS5和故事板。然后,即使重用堆栈中没有单元格,dequeueReusableCellWithIdentifier:
也会返回有效的单元格。尝试编辑情节提要中的单元格。
这个堆栈溢出问题应该可以帮助您了解会发生什么。
检查数组数据。我认为您没有正确插入数组。否则不初始化数组