TableView application terminated due to "NSInternalInconsistencyException"

I am trying to get UITableViews and everything related to it. At the moment, I have the following code:

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
     return 10; 
} 

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
     static NSString *CellIdentifier = @"Cell";
     UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


     if (cell == nil) {
         cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
     }

     [cell.textLabel setText:[NSString stringWithFormat:@"I am cell %d", indexPath.row]];

     return cell; 
}

- (IBAction)killItem {
     NSIndexPath *indexToDelete = [NSIndexPath indexPathForRow:2 inSection:0];
     [tbl deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexToDelete] withRowAnimation:UITableViewRowAnimationRight];
}

And when the "killItem" function is launched, the following error appears:

The application terminated due to the unannounced exception "NSInternalInconsistencyException", reason: "Invalid update: invalid number of lines in section 0. The number of lines contained in an existing section after updating (10) must be equal to the number of lines contained in this section before updating (10 ), plus or minus the number of rows inserted or deleted from this section (inserted 0, 1 deleted).

, tableViews , , , , tableView. , stackoverflow, , , " ", , , .

, , , . : , ?

, , :

: UITableView iPhone SDK

UITableViewCell

- "NSRangeException" , :" *** - [NSMutableArray objectAtIndex:]: 1 [0.. 0] '

[tbl reloadData], [tbl beginUpdate] ... [tbl endUpdate] killItem, , .

,

+5
2

, :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10; 
}

, , , UITableView , , , .

, , "9", 10 .

, , , NSMutableArray , - :

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [arrayWithStuff count];
}

, (removeObjectAtIndex:) , .

(Edit: Replied , , ! /, , , )

+12

, ,

// tell the table view you're going to make an update
[tableView beginUpdates];

// update the data object that is supplying data for this table
// ( the object used by tableView:numberOfRowsInSection: )
[dataArray removeObjectAtIndex:indexPath.row];

// tell the table view to delete the row
[tableView deleteRowsAtIndexPaths:indexPath 
           withRowAnimation:UITableViewRowAnimationRight];

// tell the table view that you're done
[tableView endUpdates];


endUpdate, , tableView:numberOfRowsInSection:, , beginUpdate, .

+12

All Articles