views:

700

answers:

1

I hope you can help as I'm a bit stuck as to where to look for a solution for this UITableView problem I'm having:

When I insert a new item at the top of a UITableView section using the following method (see code below) it all works beautifully apart from this glitch: The inserted row at the top of the section renders as expected - with rounded corners at the top left and right. The trouble is that the rows below are not visually updated i.e the second row/cell still has it's rounded corners whereas now it should be squared on it's top corners - please see this screen grab for clarification after the animation to insert a new row at the top of the second section has occurred. See the corners of the cells as they have not been updated.

// Amend the data source before updating the view to reflect the changes
[[self.playerData objectAtIndex: 0] removeObjectAtIndex: row];
[[self.playerData objectAtIndex: 1] insertObject:playerName atIndex:0];

// Amend the view to reflect changes
NSArray *deleteIndexPaths = [NSArray arrayWithObjects:
    [NSIndexPath indexPathForRow:row inSection:0],
    nil];

NSArray *insertIndexPaths = [NSArray arrayWithObjects:
    [NSIndexPath indexPathForRow:0 inSection:1],
    nil];

[self.playerTableView beginUpdates];
[self.playerTableView insertRowsAtIndexPaths:insertIndexPaths withRowAnimation: UITableViewRowAnimationLeft];
[self.playerTableView deleteRowsAtIndexPaths:deleteIndexPaths withRowAnimation: UITableViewRowAnimationLeft];
[self.playerTableView endUpdates];

Of course if I just sent the message: [self.playerTableView reloadData]; the view would appear correctly. However we really need this procedure to be animated to deliver a slick experience. Maybe if there was a delegated event that was fired on the completion of the insert animation I could update the view from thbe data source to get rid of the glitches, but I havn't found any hook like this.

Any help would be greatly appreciated.

+1  A: 

Have found an answer. It might not be the most efficient, though it will be fine in our circumstances as we're only dealing with a few cells here. I have fixed it by refreshing the other cells that were not being redrawn explicitly:

// Fix for cells not rendered correctly after insertion of top cell]
[self.playerTableView reloadRowsAtIndexPaths:reloadIndexPaths withRowAnimation: UITableViewRowAnimationNone];

I was probably just expecting too much of UITableView: that it would sort the corners out for me while insertRowsAtIndexPaths was being executed.

FYI info this code was placed just after the beginUpdates-endUpdates block. Anything else seems to causes as crash though not investigated that.

Thanks.

Kzrbill