gpt4 book ai didi

ios - UITableView - 以编程方式选择一行

转载 作者:行者123 更新时间:2023-11-28 22:02:04 25 4
gpt4 key购买 nike

所以我认为 StackOverflow 上有很多关于这个主题的问题,我不需要问这个问题。好吧,没有一个答案对我有用。

基本上,我试图在用户按下按钮时手动调用 -didSelectRowAtIndexPath::

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[self tableView:[viewControllers objectAtIndex:1] didSelectRowAtIndexPath:indexPath];

其中 viewControllersUITableView 的数组,已完全初始化以及所有内容。但是当我运行代码时,我在这里出错了:

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
currentUnit = [tableView cellForRowAtIndexPath:indexPath]; //on this line
[self prepareSecondPageController: [currentUnit.textLabel text]];
[unit2 setText:[NSString stringWithFormat:@"Unit Two: %@", currentCompatCategory]];
}

控制台显示:

-[UITableViewController cellForRowAtIndexPath:]: unrecognized selector sent to instance 0xc177640

(0xc177640 是 tableView)

我不知道这是否有帮助,但这是我的 indexPath 在调试器中的样子:

enter image description here

最佳答案

您向 didSelectRowAtIndexPath 方法传递了错误的参数。第一个参数必须是您的 View Controller 的 TableView 而不是 TableViewControllers 数组(根据您的异常信息,您的数组似乎不是 TableView 数组)。

[self tableView:self.tableView didSelectRowAtIndexPath:indexPath];

关于ios - UITableView - 以编程方式选择一行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24871161/

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