OGeek|极客世界-中国程序员成长平台

标题: ios - 在索引路径问题处插入行 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 10:58
标题: ios - 在索引路径问题处插入行

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

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

这里是添加点击的功能:

- (void)addTappedid)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)tableViewUITableView *)tableView numberOfRowsInSectionNSInteger)section {
    return _students.count;
}

我一直认为计数是导致问题的原因,但我监控了计数并且它保持一致。

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



Best Answer-推荐答案


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

关于ios - 在索引路径问题处插入行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9009656/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://jike.in/) Powered by Discuz! X3.4