UITableView selectRowAtIndexPath的断言失败 [英] Assertion Failure for UITableView selectRowAtIndexPath

查看:305
本文介绍了UITableView selectRowAtIndexPath的断言失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I feel like this is an issue that requires special attention... my Google-fu is pretty good but I haven't been able to get anything useful.

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

This is the simplest thing, and yet I can't seem to figure out what the problem is with it.

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

I have a UITableView. It's a subview that my VC calls _form. I'm using it for styling purposes, not really to display data. It has 2 cells.

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

On a certain event, I'm trying to select a different cell, using selectRowAtIndexPath:animated:scrollPosition.

当我这样做时,它是SIGABRTS。

When I do this, it SIGABRTS.

一个简单的例子:

- (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,但在尝试选择所需的单元格时,它会中断:

The button's title is changed, AND the table prints that the selected row is 0 or 1, but on trying to select the desired cell, it breaks:

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中的预期响应所示。除了这个以外,其他所有设置工作正常。

My assumption is that this implies something is wrong with how my table is configured, but I'm not sure what. Selecting the cells in the table normally (clicking it) is working, as indicated by the expected response in my tableView:didSelectRowAtIndexPath. Everything else works fine with how I have this set up, except this.

(另外,我还有其他人使用额外的调试信息回复,而不只是(gdb)。我怎么能得到这个?)

(Also, I other people replying with extra debug info, not just "(gdb)". How can I get this?)

谢谢!

推荐答案

tableview单元格的indexpath需要同时包含行和节。尝试使用工厂方法创建索引路径(在 NSIndexPath UIKit Additions )代之以:

An indexpath for a tableview cell needs to have both a row and a section. Try creating your index path using the factory method (defined in NSIndexPath UIKit Additions) like this instead:

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

这篇关于UITableView selectRowAtIndexPath的断言失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆