Question

OK, I have a screen in my iPhone app that looks like the following: sample screen
(source: matthewcave.com)

When the Add Notes cell is touched, I would like for the keyboard to disappear, THEN I would like it to modally display the Edit Notes Screen (which also has a keyboard, but I would like for it to animate back on screen).

Right now it animates everything at once (the keyboard never disappears, it just changes its look, and the new view modally animates on, seemingly underneath the keyboard). The whole effect functions properly, but it's a bit herky-jerky, and I think sliding the keyboard off prior to popping the modal view on screen would be smoother. I have seen other applications do what I want (things, for example) so I know it's possible.

Can anyone point me in the right direction on making each of the transitions happen individually, rather than all at once?

Edit: As requested, here's some of the code I'm using. Unfortunately, it reads almost exactly the same in Objective C as in English.

  UITableViewController* tableViewController = (UITableViewController*)tableView.dataSource;

  AddNotesViewController* addNotesViewController = [[AddNotesViewController alloc] initWithWine:[self myWine]];

  UINavigationController* addNotesNavController = [[[UINavigationController alloc] initWithRootViewController:addNotesViewController] autorelease];

  // tell the name override cell to resign if they need to
  [(NewWineViewController*)tableView.dataSource resignNameCell];

  //I'd like the animation caused by the resign to complete before proceeding.

  [tableViewController.navigationController presentModalViewController:addNotesNavController animated:YES];
Was it helpful?

Solution

I think this should work:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{
    UITextField *textField = // the field that the keyboard is up for
    [textField resignFirstResponder];

    NSTimeInterval delay = 2.0; // i.e., until keyboard has disappeared
    [self performSelector: @selector(transitionToEditNotesScreen) withObject: nil afterDelay: delay];
}

- (void) transitionToEditNotesScreen
{
    // the code you have above to bring on the modal view controller        
}

Add the following code in the controller for your Edit Notes Screen. If you want the keyboard to animate back on after the modal view has completely appeared, put it in viewDidAppear. Otherwise, put the same code in viewDidLoad or viewWillAppear.

- (void) viewDidAppear: (BOOL) animated
{
    UITextField *textField = // the field you want the keyboard to be up for
    [textField becomeFirstResponder];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top