gpt4 book ai didi

iphone - 如何使用 selectRowAtIndexPath 强制选择 UITableViewCell?

转载 作者:可可西里 更新时间:2023-11-01 06:25:08 26 4
gpt4 key购买 nike

我正在尝试使用 selectRowAtIndexPath 强制选择(突出显示)UITableViewCell..

例如,可以说我希望始终突出显示 TableView 中的第一个单元格,我在 viewDidAppear 中应用以下逻辑

[self.tableViewPrompts selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:NO scrollPosition:0];

工作得很好。但是当我尝试在应用程序的其他地方应用相同的逻辑时,单元格未被选中。我什至尝试在调用上述方法之前取消选择其他单元格,并在调用此方法之前和之后重新加载 tableview,但没有一种方法似乎有效!

我什至使用 tableview 的委托(delegate)强制调用 didSelectRowAtIndexPath.Event 这不起作用。

PS:选择单元格不会触发任何操作,我想要实现的只是突出显示所需的单元格。

我做错了什么?

非常感谢您的帮助!!

最佳答案

The selection of the cell does not trigger any action all i am trying to achieve is highlighting the desired cell.

为什么不使用单元格的突出显示属性?

UITableViewCell *cell = [self cellForRowAtIndexPath: [NSIndexPath indexPathForRow: 0 inSection: 0]];
cell.highlighted = YES;

现在无法测试,但它应该可以工作......

编辑

当然更好:改变你的 cellForRowAtIndexPath 来做到这一点

-(UITableViewCell) tableView:cellForRowAtIndexPath:
//...
if (indexPath.row == 0 && indexPath.section == 0) cell.highlighted = YES
else cell.highlighted = NO;
//...
return cell;

关于iphone - 如何使用 selectRowAtIndexPath 强制选择 UITableViewCell?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14074457/

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