以编程方式选择 tableview 行 [英] Select tableview row programmatically
问题描述
如何以编程方式选择 UITableView
行,以便
How do I programmatically select a UITableView
row so that
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath
被处决?selectRowAtIndexPath
只会突出显示该行.
gets executed? selectRowAtIndexPath
will only highlight the row.
推荐答案
来自 参考文档:
调用此方法不会导致委托接收到 tableView:willSelectRowAtIndexPath:
或 tableView:didSelectRowAtIndexPath:
消息,也不会发送 UITableViewSelectionDidChangeNotification
> 通知观察者.
Calling this method does not cause the delegate to receive a
tableView:willSelectRowAtIndexPath:
ortableView:didSelectRowAtIndexPath:
message, nor does it sendUITableViewSelectionDidChangeNotification
notifications to observers.
我会做的是:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self doSomethingWithRowAtIndexPath:indexPath];
}
然后,从您想要调用 selectRowAtIndexPath 的位置改为调用 doSomethingWithRowAtIndexPath.最重要的是,如果您希望 UI 反馈发生,您还可以另外调用 selectRowAtIndexPath.
And then, from where you wanted to call selectRowAtIndexPath, you instead call doSomethingWithRowAtIndexPath. On top of that, you can additionally also call selectRowAtIndexPath if you want the UI feedback to happen.
这篇关于以编程方式选择 tableview 行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!