简体   繁体   English

'NSInternalInconsistencyException',原因:“试图将第0行插入第0节,但更新后第0节只有0行”

[英]'NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update'

Im pretty new at iOS programming, I'm trying to make this budget app. 我在iOS编程上还很新,我正在尝试制作这个预算应用。 I want to add a instance class of my budget class to my tableview. 我想将预算类的实例类添加到表视图中。 But when I'm hitting the done button this error comes up. 但是当我点击完成按钮时,就会出现此错误。 I've been searching the forum for an answer to my problem. 我一直在论坛上搜索我的问题的答案。

So fare I've found Aby how has the same problem as I (http://stackoverflow.com/questions/11706254/nsinternalinconsistencyexception-reason-attempt-to-insert-row-0-into-section?answertab=active#tab-top) but I can't really get a clear answer/solution to my problem in that post. 到目前为止,我发现Aby的票价与我有同样的问题(http://stackoverflow.com/questions/11706254/nsinternalinconsistencyexception-reason-attempt-to-insert-row-0-into-section?answertab=active#tab -top),但在那篇文章中我无法真正解决我的问题。

I'm quit sure I know why this error happens, but how do solve it I don't know :-( Any who can help me solving this problem? 我很确定我知道为什么会发生此错误,但是我不知道如何解决它:-(有谁能帮助我解决这个问题?

I would like to post some pic of my code but stackoverflow will not allow me due to spam securing. 我想发布一些我的代码图片,但是由于垃圾邮件的保护,stackoverflow不允许我这样做。

AddBugdetViewController.m AddBugdetViewController.m

(IBAction)done
{
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil];

    Budget *budget = [[Budget alloc] init];
    budget.name = self.textField.text;
    budget.amount = [Budget convertStringToNSNumber:self.textField.text];

    [self.delegate addBudgetViewController:self didFinishAddingItem:budget];
}

BudgetViewController.m BudgetViewController.m

(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.budget.items count];
}

(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Budgets"];

    Budget *item = [self.budget.items objectAtIndex:indexPath.row];

    [self configureTextForCell:cell withChecklistItem:item];

    return cell;
}

- (void)addBudgetViewController:(AddBudgetViewController *)controller didFinishAddingItem:(Budget *)NewBudget
{
    NSLog(@"Adding budget: %@", NewBudget.name);
    NSLog(@"Budget amount: %@", NewBudget.amount);

    [self.tableView beginUpdates];

    int newRowIndex = [self.budget.items count];
    [self.budget.items addObject:NewBudget];

    NSIndexPath *indexPath = [NSIndexPath indexPathForRow:newRowIndex inSection:0];
    NSArray *indexPaths = [NSArray arrayWithObject:indexPath];
    [self.tableView insertRowsAtIndexPaths:indexPaths withRowAnimation:UITableViewRowAnimationAutomatic];

    [self.tableView endUpdates];

    [self dismissViewControllerAnimated:YES completion:nil];
}

Please tell me if you need more information to track down the problem and solve it :-) 请告诉我是否需要更多信息来查找问题并解决问题:-)

Cheers Anders 干杯安德斯

Your BudgetViewController appears to define a property named 'budget'. 您的BudgetViewController似乎定义了一个名为“ budget”的属性。 Whatever code is creating and displaying the BudgetViewController should set that property to whatever budget object should be displayed in the view controller. 无论正在创建和显示什么代码,BudgetViewController都应将该属性设置为应在视图控制器中显示的任何预算对象。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 'NSInternalInconsistencyException',原因:“试图将第4行插入第0节,但更新后第0节只有4行” - 'NSInternalInconsistencyException', reason: 'attempt to insert row 4 into section 0, but there are only 4 rows in section 0 after the update' NSInternalInconsistencyException',原因:'尝试将第0行插入第0部分,但更新后第0部分只有0行' - NSInternalInconsistencyException', reason: 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' “尝试将第0行插入第0部分,但更新后第0部分只有0行” - 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' 尝试将第0行插入第0部分,但更新后第0部分只有0行 - attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update 尝试将第 3 行插入第 0 节,但更新后第 0 节中只有 3 行 - attempt to insert row 3 into section 0, but there are only 3 rows in section 0 after the update Swift-“尝试将第0行插入第0节,但更新后第0节只有0行” - Swift - “attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” “尝试将第0行插入第0部分,但更新后第0部分只有0行”错误 - “Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update” Error 尝试插入行时“尝试将第 0 行插入第 0 节,但更新后第 0 节中只有 0 行” - "attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update" when trying to insert row 在表中插入一行时,“试图将第0行插入第0部分,但更新后第0部分只有0行” - 'attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update' when inserting a row into a table 拖放时出现错误“尝试将第 4 行插入第 1 节,但更新后第 1 节中只有 4 行” - Getting an error "attempt to insert row 4 into section 1, but there are only 4 rows in section 1 after the update" while drop and drag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM