Caught this one in testing... nasty.
I've a UITableView that I can add cells to. I've a button up in the navigation bar that calls this function:
This all works fine as long as the table view is not scrolling at the time ob the *add* button being pressed. If the UITableView is currently being animated by the scrolling motion the scroll will somewhat pause for 0.1 sec. then my animation to shift the view work for like 0.1 sec. then the scrolling takes over again.
The problem is that I end up with a view in a state sometimes difficult to recover from.
I realize these animations are intercepting each other causing this. the preferred option would be if I could cancel the scrolling animation in progress and perform my own per the function above.
If that's a no-go - any better options of doing this?
I've a UITableView that I can add cells to. I've a button up in the navigation bar that calls this function:
Code:
- (IBAction)addCell {
... create a new object to be added.
// Add it to the array containing the UITableView
[myArray addObject:newObject];
// Pop the new cell into the UITableview
[self.tableView beginUpdates];
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:[NSIndexPath indexPathForRow:[myArray count] - 1 inSection:3]] withRowAnimation:NO];
[self.tableView endUpdates];
// Scroll down to the newly created cell
// Shift the view so the keyboard doesn't cover the cell.
[UIView beginAnimations: @"anim" context: nil];
[UIView setAnimationBeginsFromCurrentState: YES];
[UIView setAnimationDuration: 0.3f];
[self.tableView setContentOffset:CGPointMake(0.0, [myArray count] - 1 * 44)];
self.tableView.frame = CGRectOffset(self.tableView.frame, 0, -keyboardOffset);
[UIView commitAnimations];
}
This all works fine as long as the table view is not scrolling at the time ob the *add* button being pressed. If the UITableView is currently being animated by the scrolling motion the scroll will somewhat pause for 0.1 sec. then my animation to shift the view work for like 0.1 sec. then the scrolling takes over again.
The problem is that I end up with a view in a state sometimes difficult to recover from.
I realize these animations are intercepting each other causing this. the preferred option would be if I could cancel the scrolling animation in progress and perform my own per the function above.
If that's a no-go - any better options of doing this?
Last edited: