在XCode 4.3.3中为Table View Cell添加字幕样式

时间:2012-06-21 10:40:29

标签: iphone uitableview

我有一个让我发疯的问题。我认为这很容易解决,但我无法弄清楚。我做了一个简单的表视图,其中包含两个数组的单元格。一个用于单元格中的主要文本,另一个用于单元格中的字幕。但问题是当我用字幕样式创建单元格时,我在运行应用程序时看不到它们。 这是我的代码:

- (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块时,它不会进入块状态。这意味着“细胞”在那一刻并不是零。问题是为什么会发生这种情况,我该如何解决这个问题?所有的帮助将不胜感激。

2 个答案:

答案 0 :(得分:1)

我假设您使用的是iOS5和故事板。然后,即使在重用堆栈中没有一个,dequeueReusableCellWithIdentifier:也会返回一个有效的单元格。尝试在故事板中编辑单元格。

stackoverflow question应该可以帮助您了解会发生什么。

答案 1 :(得分:0)

检查你的数组数据。我认为你没有正确插入数组。否则你不是初始化数组