如何以编程方式控制UITableViewCell样式?

时间:2012-10-17 04:45:57

标签: uitableview

使用StoryBoard我有这种情况,代码如下:

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
//        cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text=[[cityArray objectAtIndex:indexPath.row] valueForKey:@"CELL_TEXT"];
    cell.detailTextLabel.text=[[cityArray objectAtIndex:indexPath.row] valueForKey:@"DETAIL_TEXT"];

我的测试告诉我,无论我在执行alloc时使用UITableViewCellStyleDefault或UITableViewCellStyleSubtitle这一事实,上面的两行最后一行都能正常工作。

这两个最后一行仅取决于我在StoryBoard中的设置(单元格样式是否为字幕)。

现在我的问题是:我如何编程控制单元格的样式,从UITableViewCellStyleDefault转到UITableViewCellStyleSubtitle,反之亦然?

显然,仅更改alloc,不起作用;我找不到任何我可以设置的财产。

1 个答案:

答案 0 :(得分:0)

如果您正在使用带有原型单元格的Storyboard,则单元格不会为零。它将永远被创建。要么不在故事板中使用原型单元格,要么从故事板中分配不同的原型单元格。

相关问题