简体   繁体   English

方法selectRow(at:animated:scrollPosition :)不调用tableView(_:didSelectRowAt :)

[英]The method selectRow(at:animated:scrollPosition:) doesn't call tableView(_:didSelectRowAt:)

I want to set the default selected row by selectRow(at:animated:scrollPosition:) . 我想通过selectRow(at:animated:scrollPosition:)设置默认的选定行。 But the document said calling this method does not cause the delegate to receive a tableView(_:didSelectRowAt:) message. 但是文档说,调用此方法不会导致委托接收到tableView(_:didSelectRowAt:)消息。

How to set the default selected row and call the tableView(_:didSelectRowAt:) ? 如何设置默认的选定行并调用tableView(_:didSelectRowAt:)

我只需要以编程方式调用tableView(_:didSelectRowAt:)

This will work for you. 这将为您工作。

tableView.delegate = self

In viewWillAppear() or after few milliseconds of viewDidLoad, call this: 在viewWillAppear()中或在viewDidLoad几毫秒后,调用此命令:

tableView.selectRow(at: <IndexPath?>, animated: <Bool>, scrollPosition: <UITableViewScrollPosition>)

Share you full source code here, so can give you better suggestion. 在此处分享您的完整源代码,这样可以给您更好的建议。

You can call tableView(_:didSelectRowAt:) 您可以调用tableView(_:didSelectRowAt:)

after selectRow(at:animated:scrollPosition:) selectRow(at:animated:scrollPosition:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 tableviewcell 的 isSelected 方法和 tableview 的 selectRow(at:animated:scrollPosition:) 有什么区别 - what is the different between isSelected method of tableviewcell and selectRow(at:animated:scrollPosition:) of tableview 模态视图中的 TableView 未检测到 didselectrowat - TableView inside modal view doesn't detect didselectrowat 何时调用 tableView.selectRow 以避免 UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate - When to call tableView.selectRow to avoid UITableViewAlertForCellForRowAtIndexPathAccessDuringUpdate tableView(_ tableView:UITableView,didSelectRowAt indexPath:IndexPath)将UITapGestureRecognizer添加到自定义UITableViewCell时不起作用 - tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) Doesn't work when I add a UITapGestureRecognizer to my custom UITableViewCell 当我使用 UIAdaptivePresentationControllerDelegate (Swift 5) 时,tableView.selectRow(...) 不起作用 - tableView.selectRow(...) doesn't work when I use UIAdaptivePresentationControllerDelegate (Swift 5) 动态文本字段未在TableView didSelectRowAt方法中缓存 - Dynamic textfield not getting cached in TableView didSelectRowAt method 无法让didSelectRowAt用于TableView - Can't get didSelectRowAt to work for TableView didSelectRowAt不会影响cellForRowAt - didSelectRowAt doesn't affect cellForRowAt PickerVIew.selectRow不起作用 - PickerVIew.selectRow doesn't work TableView scrollToRowAtIndexPath:动画:并不总是向下滚动 - TableView scrollToRowAtIndexPath: animated: doesn't always scroll down
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM