2

I have a view controller. It is pushed by another's UINavigationController. In ViewController.m:

- (BOOL)canBecomeFirstResponder { 
    return YES;
}

- (void)viewDidAppear:(BOOL)animated {
    [self.view becomeFirstResponder];
    NSLog(@"%d", [self.view isFirstResponder]);
    [super viewDidAppear:animated];
}

It's always 0. Why?

Matt Becker
  • 2,338
  • 1
  • 28
  • 36
SentineL
  • 4,682
  • 5
  • 19
  • 38
  • What is self.view? Not all UIView subclasses can become first responder. – jrturton Nov 08 '11 at 10:45
  • is't a usual viewController's view. i'm trying to make a shake> useing that question: (http://stackoverflow.com/questions/150446/how-do-i-detect-when-someone-shakes-an-iphone) It's just doesn't work at all. – SentineL Nov 08 '11 at 11:00

1 Answers1

6

Your view has to accept first responder status. This is implemented in your view's subclass code, you have to override canBecomeFirstResponderand return YES:

- (BOOL)canBecomeFirstResponder 
{ 
    return YES; 
} 
jrturton
  • 118,105
  • 32
  • 252
  • 268
  • you'r right. I tryed to set this methods to ViewController, and this is wrong. now my ViewController.view IS firest responder, but shake doesn't work anyway. – SentineL Nov 08 '11 at 11:49