且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

以编程方式选择 tableview 行

更新时间:2023-08-28 21:22:40

来自 参考文档:

调用此方法不会导致委托接收到 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.