The code you describe has the same error inside as mine had.

The problematic thing is, that this piece of code
Quote:
|
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
|
launches its own animation though you use
UITableViewRowAnimationNone it still kicks of an animation. So, any deletion or insertion sports an animation (which is fine) but you have to wait until they are finished before touching the cells again with some reload. I worked around this by kicking of a timer which delays my message.
That solved it for me!
regards,
Helge
Quote:
Originally Posted by eatenbyrats
I'm trying to implement a TableView that has alternating backgrounds on rows to help readability, but I'm having difficulty getting rendering subsequent to re-ordering working.
Re-drawing after deletion works without any problems, but I get unpredictable results when I call tableView:reloadRowsAtIndexPaths:withRowAnimation: in the implementation of tableView:moveRowAtIndexPath:toIndexPath:
Code:
// Create table cells with alternating row appearance
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellID];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellID] autorelease];
extraneous detail removed...
}
BOOL oddRow = (indexPath.row % 2 == 0);
NSString *backgroundImagePath = [[NSBundle mainBundle] pathForResource:oddRow ? @"oddbkd" : @"evenbkd" ofType:@"png"];
UIImage *backgroundImage = [[UIImage imageWithContentsOfFile:backgroundImagePath] stretchableImageWithLeftCapWidth:0.0 topCapHeight:1.0];
cell.backgroundView = [[[UIImageView alloc] initWithImage:backgroundImage] autorelease];
cell.backgroundView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
cell.backgroundView.frame = cell.bounds;
return cell;
}
// Delete rows
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[testData removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone];
}
// Reload visible cells to force a redraw
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
}
// Rearrange rows
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
id tempObject = [[testData objectAtIndex:sourceIndexPath.row] retain];
[testData removeObjectAtIndex:sourceIndexPath.row];
[testData insertObject:tempObject atIndex:destinationIndexPath.row];
[tempObject release];
// Blank cells, stack dumps, exceptions from nested setEdit:withAnimation: calls...
[tableView reloadRowsAtIndexPaths:[tableView indexPathsForVisibleRows] withRowAnimation:UITableViewRowAnimationNone];
}
Any suggestions appreciated- I've tried telling the UITableViewCell.view itself to redraw and reloading the whole table (not exactly desirable) without success.
|