【发布时间】:2014-09-18 09:42:11
【问题描述】:
'NSInternalInconsistencyException',原因:'无效更新:第 0 节中的行数无效。更新后现有节中包含的行数 (6) 必须等于该节中包含的行数之前update (6),加上或减去从该节插入或删除的行数(1 插入,0 删除),加上或减去移入或移出该节的行数(0 移入,0 移出)。
->@property (nonatomic ,strong) NSMutableArray *name;
- (id)initWithFrame:(CGRect)frame viewName:(NSInteger)viewDecide datasourceName:(NSMutableArray *)nameRef
{
}
当我在这个类中初始化上面的 MutableArray 喜欢
self.name=[NSMutableArray alloc]initWithObjects:@"1",@"2",@"3", nil];
然后使用表格视图编辑委托方法,一切正常,当我单击按钮时,表格进入编辑模式并删除和插入。
但是当我使用我在上述方法中传递的数据源初始化相同的数组时。 tableview 中的数据正确呈现,但是当我单击编辑按钮时它崩溃了。
注意:- 我用过 对于行数-
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return[self.name count];
}
用于插入
[strongSelf.tableViewDataView1 insertRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationLeft];
and for deleting i used
[strongSelf.tableViewDataView1 deleteRowsAtIndexPaths:[NSArray arrayWithObjects:[NSIndexPath indexPathForRow:0 inSection:0], nil] withRowAnimation:UITableViewRowAnimationLeft];
:-strongSelf 被使用是因为这发生在一个块内。
【问题讨论】:
-
这是因为您在调用插入部分时并未实际将项目添加到数组中,因此您在
-tableView:numberOfRowsInSection:中返回的值并没有增加,但您告诉 tableView 插入一行。 -
是的,我刚刚得到它,但是谢谢是的,我必须在点击编辑按钮时更改计数谢谢您的回复
标签: ios uitableview