A: 

In the code you posted, your loop index runs from 0 to 4, which suggests that it would delete all of the rows in section 1, and then add five new rows to section 2. Since each section already has a row 0, this would add a second instance of section 2, row 0 to the table.

I would suggest having your loop run from 1 to 4:

for (int i=1; i<5; i++)
{
    // ...
}
e.James
A: 

Hey eJames, thanks for your comment - a really valid point!!

I thought for a minute it might solve my problem - but I still have the same trouble. I think there actually might be a iPhone but when you try and remove items from one section and adding them to another section at the same time...

Nick Cartwright
This should probably be a comment on eJames' response, rather than a response in its own right. :)
Chris Hanson
Agreed, but them's the rules here. You can't leave comments with less than 50 rep.
e.James
A: 

I seem to remember that numberOfRowsInSection: will get called when you call deleteRows or insertRow, you need to be really careful that the reality numberOfRowsInSection cliams matches your changes. In this case you may want to try moving the iSelectedSection = [indexPath section]; line to after the endUpdates.

superfell
+1  A: 

I don't remember where I read this but I believe you shouldn't perform table row updates (insertions and deletions) from inside one of the table view delegate functions. I think a better alternative would be to do a performSelectorOnMainThread passing along the necessary information needed to perform the updates as an object. Something like:

- (void)tableView:(UITableView *)tableView 
  didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    // ....
    [self performSelectorOnMainThread: @selector(insertRows:)
                           withObject: someObjectOrNil]; // double check args
}

- (void) insertRows: (NSObject*)someObjectOrNil {
    [tableView beginUpdates];
    // update logic
    [tableView endUpdates];

    // don't call reloadData here, but ensure that data returned from the 
    // table view delegate functions are in sync
}
codelogic
A: 

FYI: This bug seems to have been fixed completely with the 2.2 iPhone update. Thanks Apple! Nick.

Nick Cartwright
+2  A: 

Struggled to get this to work. Here's my code to add a row to my tableView (artistsToAdd is the dataSource for the tableView. The number of rows is set with [artistsToAdd count])

NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
[tableView beginUpdates];
[artistsToAdd insertObject:[artistField text] atIndex:0];
[tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationTop];
[tableView endUpdates];
Sam V