以编程方式选择 tableview 行 [英] Select tableview row programmatically

查看:29
本文介绍了以编程方式选择 tableview 行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何以编程方式选择 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: or tableView:didSelectRowAtIndexPath: message, nor does it send UITableViewSelectionDidChangeNotification 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆