【发布时间】:2012-06-21 10:40:29
【问题描述】:
我有一个让我发疯的问题。我认为这很容易解决,但我无法弄清楚。我制作了一个简单的表格视图,其中包含根据两个数组的单元格。一个用于单元格中的正文,另一个用于单元格中的副标题。但问题是当我用字幕样式制作单元格时,运行应用程序时看不到它们。 这是我的代码:
- (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 块时,它并没有进入块。这意味着“细胞”在那一刻不是零。问题是为什么会发生这种情况,我该如何解决?我们将不胜感激您的所有帮助。
【问题讨论】:
-
尝试将
NSLog(@"%@",[hop objectAtIndex:indexPath.row]);和NSLog(@"%@",[hop2 objectAtIndex:indexPath.row]);放在cell.textLabel.text=...之前,如果不为零,请在控制台中检查。 -
它们不是零。问题是应用程序没有进入 if 语句。这使得 detailTextLabel 不存在。
标签: iphone uitableview