gpt4 book ai didi

ios - 带有 AccessoryView 的单个 UITableViewCell

转载 作者:行者123 更新时间:2023-11-28 20:30:10 25 4
gpt4 key购买 nike

我正在尝试构建一个 UITableView,每个单元格中都有一些长文本。单元格没有 AccessoryView,除了一个单元格(第 8 个),这是一种打开详细 View 的按钮。

考虑这段代码:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
CGSize size = [[quotes objectAtIndex:indexPath.row] sizeWithFont:16 constrainedToSize:CGSizeMake(self.view.frame.size.width, CGFLOAT_MAX)];
return size.height+20;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

static NSString *CellIdentifier = @"Cell";

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

cell.textLabel.lineBreakMode = UILineBreakModeWordWrap;
cell.textLabel.numberOfLines = 0;
cell.textLabel.text = [quotes objectAtIndex:indexPath.row];

if(indexPath.row==7){
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
}

return cell;
}

它有效,但问题是当我滚动到表的底部(第 8 行也是最后一行)然后我回到上面时,另一个 AccessoryView 被添加到一个随机点(更多或少了第三个单元格,但我不知道它是在里面还是随机漂浮)。它与 iOS 的单元重用有关吗?我该如何避免?

提前致谢。

最佳答案

除了您希望公开的单元格之外,您必须为每个单元格明确设置不公开按钮。这样,当单元格在其他地方被重用时,它的披露指示符将被删除:

 if(indexPath.row==7){
[cell setAccessoryType:UITableViewCellAccessoryDetailDisclosureButton];
}else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}

关于ios - 带有 AccessoryView 的单个 UITableViewCell,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12451794/

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