在索引路径处插入行问题 [英] Inserting Row at Index path issues

查看:53
本文介绍了在索引路径处插入行问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个设置为数据层次结构的iOS应用。我在添加和删除对象甚至过渡到下一页的第一页上都没有问题。该问题出现在第二页上,该页的设置与第一页完全相同。当我按下添加按钮添加对象时,程序崩溃并发回错误SIGABRT。

I am creating an iOS app that is set up as a hierarchy of data. I have no issues on the first page adding and deleting objects or even transitioning to the next page. The problem occurs on the second page which is set up exactly like the first. When I press the add button to add an object the program crashes and sends back the error SIGABRT.

[self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES]; << crashes on this line

此处是点击添加的功能:

here is the function add tapped:

- (void)addTapped:(id)sender {
    StudentDoc *newDoc = [[[StudentDoc alloc] initWithTitle:@"New Student" rating:0 thumbImage:nil fullImage:nil] autorelease];
    [_students addObject:newDoc];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:_students.count-1 inSection:0];
    NSArray *indexPaths = [NSArray arrayWithObject:indexPath];    
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:YES];

    [self.tableView selectRowAtIndexPath:indexPath animated:YES scrollPosition:UITableViewScrollPositionMiddle];
    [self tableView:self.tableView didSelectRowAtIndexPath:indexPath];
 }

节中的行数:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return _students.count;
}

我一直以为计数是导致问题的原因,

I have been under the impression that the count is what is causing the problem, but I have monitored the count and it stays consistent.

总的来说,我不知道为什么它会崩溃,因为它之前的页面使用的功能完全相同。该页面上的对象。有任何想法吗?

Overall I have no idea why it is crashing at this point because the page before it uses the exact same function to add objects on that page. Any ideas?

推荐答案

通常,如果您弄乱了数组或行索引,则希望在控制台中记录一个异常,不是SIGABRT。您是否在Xcode中启用了NSZombies和Break-on-exceptions?这可能有助于诊断问题。

Normally if you'd messed up your array or row indexes you'd expect an exception to be logged in the console, not a SIGABRT. Have you enabled NSZombies and break-on-exceptions in Xcode? That may help to diagnose the issue.

这篇关于在索引路径处插入行问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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