gpt4 book ai didi

iPhone didSelectRowAtIndexPath 没有触发

转载 作者:行者123 更新时间:2023-12-01 18:33:52 27 4
gpt4 key购买 nike

所以我试图默认在我的 View 首次加载时选择 tableView 中的第一行。我正在这样做我的 viewWillAppear 方法:

NSIndexPath *tempPath= [NSIndexPath indexPathForRow:0 inSection:0];

[theTable.delegate tableView:theTable didSelectRowAtIndexPath:tempPath];

哪个会触发该方法,但单元格不会保持选中状态。这会触发正确的方法并在那里执行代码,我永远不会取消选择它。用户按下另一个单元格后,它会保持正确选中状态。只是不是第一次。有谁知道可能导致这种奇怪的原因?我什至尝试过这样做:
[[theTable.delegate tableView:theTable cellForRowAtIndexPath:tempPath] setSelected:YES];

想法?

最佳答案

首先,您不应该像那样直接调用委托(delegate)方法。

如果您确实需要以编程方式选择一个单元格(就像 Mail 应用程序那样),请使用 selectRowAtIndexPath 方法:

[theTable selectRowAtIndexPath:tempPath animated:YES scrollPosition:UITableViewScrollPositionBottom];

关于iPhone didSelectRowAtIndexPath 没有触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4080789/

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