gpt4 book ai didi

ios - UITableView selectRowAtIndexPath 断言失败

转载 作者:可可西里 更新时间:2023-11-01 03:37:03 24 4
gpt4 key购买 nike

我觉得这是一个需要特别注意的问题......我的Google-fu很好,但我还没有得到任何有用的东西。

这是最简单的事情,但我似乎无法弄清楚它的问题所在。

我有一个 UITableView。这是我的 VC 调用 _form 的 subview 。我将它用于样式目的,而不是真正用于显示数据。它有 2 个单元格。

在某个事件中,我尝试使用 selectRowAtIndexPath:animated:scrollPosition 选择不同的单元格。

当我这样做时,它发出信号。

一个简单的例子:

- (IBAction)submitClicked:(id)sender
{
[_submit setTitle:@"Wha!?" forState:UIControlStateNormal];
NSIndexPath *row = [NSIndexPath indexPathWithIndex:0];
NSLog(@"%d", [[_form indexPathForSelectedRow] row]);
[_form selectRowAtIndexPath:row animated:YES scrollPosition:YES];
}

按钮的标题已更改,表格打印所选行为 0 或 1,但在尝试选择所需的单元格时,它会中断:

2012-03-09 21:57:39.905 <omitted>[16329:207] 0
2012-03-09 21:57:39.908 <omitted>[16329:207] *** Assertion failure in -[NSIndexPath row], /SourceCache/UIKit_Sim/UIKit-1912.3/UITableViewSupport.m:2598
(gdb)

我的假设是,这意味着我的表的配置方式有问题,但我不确定是什么。正常选择表中的单元格(单击它)是有效的,如我的 tableView:didSelectRowAtIndexPath 中的预期响应所示。其他一切都与我的设置相得益彰,除了这个。

(此外,我其他人回复了额外的调试信息,而不仅仅是“(gdb)”。我怎样才能得到这个?)

谢谢!

最佳答案

tableview 单元格的索引路径需要同时包含行和部分。尝试使用工厂方法(在 NSIndexPath UIKit Additions 中定义)创建索引路径,如下所示:

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[_form selectRowAtIndexPath:indexPath animated:YES scrollPosition:YES];

关于ios - UITableView selectRowAtIndexPath 断言失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9644359/

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