gpt4 book ai didi

objective-c - 如何为同一个表格中的不同单元格设置不同的 UITableViewCell Style?

转载 作者:塔克拉玛干 更新时间:2023-11-02 09:51:18 24 4
gpt4 key购买 nike

您好,我正在实现一个 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com