作者热门文章
- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
您好,我正在实现一个 UITableView。我打算根据特定条件对不同的单元格集使用不同的 UITableViewCellStyle(请参见下面的代码片段)
if (cell == nil)
{
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:PlaceholderCellIdentifier]autorelease];
cell.textLabel.font = [UIFont boldSystemFontOfSize:14];
cell.textLabel.lineBreakMode = UILineBreakModeCharacterWrap;
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
cell.textLabel.numberOfLines = 0;
}
if ([genericObj.type isEqualToString:@"question"])
{
//I want to user UITableViewCellStyleValue1
}
else if([genericObj.type isEqualToString:@"topic"])
{
//I want to user UITableViewCellStyleValue2
}
else //user
{
//I want to user UITableViewCellStyleSubtitle
}
谁能告诉我如何相应地更改 uitableviewcellstyle?
最佳答案
UITableViewCell 的样式在初始化后就不能再改变了。
改为使用不同的重用标识符。
将 if then else 放在 if (cell == nil) 行上方。从那些 dequeue 中取出您需要的不同类型的单元格。
如果单元格为零,则在另一个 if then else block 中初始化您需要的单元格。
关于objective-c - 如何为同一个表格中的不同单元格设置不同的 UITableViewCell Style?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7964594/
我是一名优秀的程序员,十分优秀!