gpt4 book ai didi

swift - selectRowAtIndexPath 不能快速工作

转载 作者:搜寻专家 更新时间:2023-10-31 08:26:28 24 4
gpt4 key购买 nike

我正在尝试以编程方式选择 TableView 行。我一直在关注此处的文档和其他引用资料,但它不起作用。我没有收到错误,只是没有选择行。

注意:目前我只是尝试手动选择一行。

我是否正确使用了委托(delegate)、数据源和 NSIndexPath?

 override func viewDidLoad() {
super.viewDidLoad()

var myPath = NSIndexPath(forRow: 1, inSection: 0)
myTableView.selectRowAtIndexPath(myPath, animated: false, scrollPosition: UITableViewScrollPosition.None)

enter image description here

最佳答案

很可能在调用 viewDidLoad 时 TableView 尚未准备好或未填充。

viewDidAppearviewWillAppear 中试试:

override func viewDidAppear(_ animated: Bool){
let myPath = NSIndexPath(row: 1, section: 0)
tableView.selectRow(at: myPath as IndexPath, animated: false, scrollPosition: UITableViewScrollPosition.none)
}

关于swift - selectRowAtIndexPath 不能快速工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31983977/

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