Note that there are some explanatory texts on larger screens.

plurals
  1. POhow does one make a subview firstResponder
    primarykey
    data
    text
    <p>i am trying to get a subview to become firstResponder. my understanding is that this is done in its viewDidAppear method, like so:</p> <pre><code>- (void)viewDidAppear { [self becomeFirstResponder]; } </code></pre> <p>while overriding canBecomeFirstResponder to return YES:</p> <pre><code>- (BOOL)canBecomeFirstResponder { return YES; } </code></pre> <p>however, when i insert the subview in its parent view's viewDidLoad method:</p> <pre><code>- (void)viewDidLoad { subViewController = [[SubViewController alloc] init]; [self.view insertSubview: subViewController.view atIndex: 0]; [subViewController viewDidAppear: NO]; [super viewDidLoad]; </code></pre> <p>}</p> <p>(i call viewDidAppear manually, because it does not get triggered automatically), the subview does not become firstResponder.</p> <p>why does the subview not become firstResponder? and how can i make it firstResponder?</p> <p>thanks,</p> <p>mbotta</p> <p>btw, this is a rewrite of my original question:</p> <p>i am trying to build an iphone app where a rootviewcontroller object manages two subviews, one of which should react to a user shaking his iphone.</p> <p>after some digging, i concluded the subview must be made firstResponder in its view controller's viewDidAppear method. moreover, the canBecomeFirstResponder method should be modified to return YES.</p> <p>so here's what happens: i instantiate the rootviewcontroller in the app delegate. in its viewDidLoad method, i tell it to addSubView firstViewController. all of this works just beautifully.</p> <p>however, firstViewController does not react to any shaking. i sprinkled some NSLogs around and found that while we DO tell firstViewController in canBecomeFirstResponder to return YES, and while we DO tell it to [self becomeFirstResponder] in viewDidAppear, in actual fact, it is <em>not</em> the firstResponder.</p> <p>so, my questions are: 1) does a subview actually need to be firstResponder in order to react to shaking? a) if not, how does one make a subview react without being firstResponder? 2) how does one make a subview firstResponder?</p> <p>what makes this interesting is that if i perform the same sequence (canBecomeFirstResponder, [self firstResponder], motionBegan:) in a different project with only one view controller, it all works flawlessly. clearly, i must be hitting a design flaw of my own making.</p> <p>thanks,</p> <p>mbotta</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload