UIViewController - can't become first responder

前端 未结 3 810
情歌与酒
情歌与酒 2020-12-15 00:34

anyone knows why UIViewController wouldn\'t become first responder when I run this code:

[self becomeFirstResponder];
NSLog(@\"is first resp: %i\",[self isFi         


        
3条回答
  •  独厮守ぢ
    2020-12-15 01:08

    Update

    As I suspected, I assumed wrong about UIViewController/firstResponder usage. This thread in the apple dev forums talks specifically about getting shaking to work.

    Original Answer

    Call becomeFirstResponder on the UI element that you want to respond. The events will automatically get forwarded to the UIViewController as long as no other objects in the chain implement the touches methods (or at least keep forwarding them up the chain).

    Side note: To build on the comments of others, it really doesn't make sense for a UIViewController to be the "first" responder. The first responder should be an object with an on screen representation (a UIView or one of its subclasses).

    Although this may be a completely incorrect statement, there may be undocumented behavior in UIViewController that prevents it from becoming the firstResponder because of these issues (Someone smarter than me may be able to verify the validity of this).

提交回复
热议问题