English 中文(简体)
NS Internal Inconsistency Exception while deleting/inserting therow in UITableView
原标题:NSInternalInconsistencyException while deleting/inserting rows in UITableView


I need to create an app with tableView. For now I can just load/reload all data in my table. To add/delete operation tableView has editing mode. But the problem is that in this mode tableView shows standart add/delete buttons. But I don t need this buttons. In Apple tutorial I found other way to do add/delete row like this:

[data removeObjectAtIndex:0];
[data addObject:[[chooseTypeCell alloc]init]];
NSIndexPath *insertIndexPaths=[NSIndexPath indexPathForRow:[data count] inSection:0]; 
NSIndexPath *deleteIndexPaths=[NSIndexPath indexPathForRow:0 inSection:0];
[[self view] beginUpdates];
[[self view] insertRowsAtIndexPaths:[NSArray arrayWithObject:insertIndexPaths] withRowAnimation:UITableViewRowAnimationRight];
[[self view] deleteRowsAtIndexPaths:[NSArray arrayWithObject:deleteIndexPaths] withRowAnimation:UITableViewRowAnimationFade];
[[self view] endUpdates];

但造成错误=(......)。

因无一例外而终止职务:无有效表格观点更新。 该申请要求更新表格中与数据来源所提供的数据不符的意见。

在我的案件中,使用物体的Im,该物体是UITableViewController的子产物,有UITableViewSource和UITableViewDelegate规程。 就此而言,意见变量与我的可调意见有关。 因此,UITableView与唯一的控制器连接。 在这位控制员中,我界定了这些方法:

#pragma mark - Table view data source

#######>>>>> right code =)

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section


#######>>>>> in comment section

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle
forRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

#######>>>>> without any code or cap

- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index

- (NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section

- (NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
toIndexPath:(NSIndexPath *)toIndexPath

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView

- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView

#pragma mark - Table view delegate

#######>>>>> right code =)

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath  
#######>>>>> in comment section

 - (NSIndexPath *)tableView:(UITableView *)tableView willDeselectRowAtIndexPath:(NSIndexPath *)indexPath 

 - (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath

#######>>>>> without any code or cap

- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath
*)indexPath

- (void)tableView:(UITableView *)tableView willBeginEditingRowAtIndexPath:(NSIndexPath *)indexPath

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section

- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath
*)indexPath

- (NSIndexPath *)tableView:(UITableView *)tableView targetIndexPathForMoveFromRowAtIndexPath:(NSIndexPath
*)sourceIndexPath toProposedIndexPath:(NSIndexPath *)proposedDestinationIndexPath

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath

- (NSInteger)tableView:(UITableView *)tableView indentationLevelForRowAtIndexPath:(NSIndexPath *)indexPath

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section

- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView didEndEditingRowAtIndexPath:(NSIndexPath *)indexPath

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath

Any ideas what s wrong?

最佳回答

否则:

Assertion failure in -[_UITableViewUpdateSupport _computeRowUpdates], /SourceCache/UIKit/UIKit-1912.3/UITableViewSupport.m:386 Terminating app due to uncaught exception NSInternalInconsistencyException , reason: Invalid table view update. The application has requested an update to the table view that is inconsistent with the state provided by the data source.

May appear because your UITable-Data class is wrong defined. You need to pay your attention to this methods:

-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

你们还需要检查你的算术。 所有指数都必须从后数据结构上提取。

文件:

Deletion and reloading operations within an animation block specify which rows and sections in the original table should be removed or reloaded; insertions specify which rows and sections should be added to the resulting table. The index paths used to identify sections and rows follow this model. Inserting or removing an item in a mutable array, on the other hand, may affect the array index used for the successive insertion or removal operation; for example, if you insert an item at a certain index, the indexes of all subsequent items in the array are incremented.

在我的案件中:insertRowsAtIndexPaths功能出现错误。 由于我的所有改动(我的数据)都在执行时适用。 我的电文Cell的新立场是([数据]-1),而我只是使用[数据]。

感谢您的关注。

问题回答

暂无回答




相关问题
Table cell stretching

I have two columns in my table with equal width (50%, 50%). I am showing search results URL in them. For big urls the columns are stretching and destroying the layout. Any suggestion to the problem?

Add Semicolon to each value (each line) in a cell

I have the following values in a single cell let be A1 1234 567 454 Likewise all the A(N) are filled with values. N various from 1000 to 1500 I want this to get converted as 1234;567;454 Any ...

Blank when NaN in jqGrid cells

How to set blank instead of NaN in jqGrid cells ? Using formatter ? Is there an example?

BeginEdit of a specific Cell from code behind

Is possibile begin edit of a specific cell from code behind with DataGrid control (WPF Toolkit)? I have to enable the celledittemplate of first cell of selected row after a button action...how can I ...

提供数据

我想让浏览头和一栏头目从使用因特网部分数据GridView的图像中获得一个习俗背景。 甚至有可能这样做吗? 如果是,如何?

热门标签