tags:

views:

332

answers:

2

I'm making my app shake-gesture-compatible by doing this in my UIViewController:

- (void)viewWillAppear:(BOOL)animated
{
    [self.view becomeFirstResponder];
    [super viewWillAppear:animated];
}

The problem is that when I flip to another view (I'm using the "Utility App" template which has a flipside view and a root view controller to manage them both) the shake gesture ceases to work when I come back.

I see that the viewWillAppear method is called, it just doesn't seem that the view regains first responder status the second time around.

+1  A: 

Who knew .. you have to put the call to becomeFirstResponder in viewDidAppear instead of viewWillAppear.

sehugg
I had the same problem! I think I found the answer on one of the App Dev forums..
Denis M
A: 

Yup, that confirms it for me ... I was trying to set the controllers as firstResponder from the application delegate. Meanwhile, I found it very helpful for debugging to sprinkle this log statement in strategic methods.

NSLog(@"%s: I %s first responder! (%@)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);

Also, to allow me to trigger it at arbitrary times, I enabled the "orientation" method and put it in there.

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
NSLog(@"%s: I %s first responder! (%@)", __FUNCTION__, [self isFirstResponder] ? "am" : "am not", self);
return YES;
}
mobibob