简体   繁体   English

成为第一响应者应用程序代理不起作用

[英]Become first responder app delegate not working

My situation goes as follows: I have an app which has a PIN screen implemented. 我的情况如下:我有一个实现了PIN屏幕的应用程序。 Its nothing high-tech just basic 4 UITextField s and implemented logic via UITextFieldDelegate - it works. 它没有什么高科技,只是基本的4个UITextField和通过UITextFieldDelegate实现的逻辑-它可以工作。

I'm showing this screen in app delegate on -(void)applicationWillEnterForeground:(UIApplication *)application event. 我在-(void)applicationWillEnterForeground:(UIApplication *)application事件的应用程序委托中显示此屏幕。 I am using MMDrawerController from github (link: https://github.com/mutualmobile/MMDrawerController ) as the main view controller. 我正在使用来自github的MMDrawerController (链接: https : //github.com/mutualmobile/MMDrawerController )作为主视图控制器。 If the current view presented when the application enters background and foreground again is this MMDrawerController then the becomeFirstResponder is not working - it doesn't show the keyboard. 如果在应用程序再次进入背景和前景时当前显示的视图是此MMDrawerController那么becomeFirstResponder无法正常工作-它不会显示键盘。 If there is another view controller presented on top of drawer controller the when entering foreground (let's say settings view) then keyboard appears normally. 如果在抽屉控制器的顶部有另一个视图控制器,则进入前景时(例如设置视图),键盘将正常显示。

I have tried NSLog ing the canBecomeFirstResponder property and its set to YES . 我尝试了NSLogcanBecomeFirstResponder属性并将其设置为YES What is going on? 到底是怎么回事? How to fix this? 如何解决这个问题?

I can paste code if needed but its nothing ambiguous. 如果需要,我可以粘贴代码,但没有任何歧义。 Just plain call becomeFirstResponder . 只需简单地调用becomeFirstResponder

EDIT: 编辑:

To explain things a bit more clearly. 为了更清楚地解释事情。 rootViewController is a view controller caleed LoginViewController and it alloc-init s the sidebar and the center view controllers, alloc-init s the drawer controller and hooks everything up so it works. rootViewController是caleed视图控制器LoginViewController和它alloc-init S上的侧栏和中心视图控制器, alloc-init S中的抽屉控制器和钩一切行动所以它的工作原理。 The app delegate view is actually a PIN screen which pops up when the app enters foreground. 应用程序委托视图实际上是一个PIN屏幕,当应用程序进入前台时会弹出。 Now the keyboard appears like it should for the first time the drawer is visible. 现在,键盘看起来像它应该第一次显示抽屉一样。

When the user pops up SettingsViewController (yes, this is another view controller accessible from the sidebar view controller) it works as well. 当用户弹出SettingsViewController (是的,这是可以从边栏视图控制器访问的另一个视图控制器),它也可以正常工作。 But when the user dismisses the settings view controller keyboard doesn't appear anymore. 但是当用户关闭设置时,视图控制器的键盘将不再显示。 It has to do something with the drawer cause I tried without it and it worked (but I only had sidebar or center view controller visible). 它必须与抽屉做些事情,因为我尝试了不使用它并且它起作用了(但是我只有侧边栏或中央视图控制器可见)。

Ideally you would want to access the textField within the MMDrawerControllers currentView. 理想情况下,您需要访问MMDrawerControllers currentView中的textField。 I have achieved something similar with this implementation: 通过此实现,我已经实现了类似的功能:

In your app delegate store a reference to the DrawerController like so: 在您的应用程序委托中,存储对DrawerController的引用,如下所示:

In AppDels interface: 在AppDels界面中:

@property(nonatomic, strong) MMDrawerController *appDrawController;

Then after you create the local drawer controller in didFinishLaunching (if you followed the setup instructions for this library): 然后,在didFinishLaunching中创建本地抽屉控制器之后(如果您遵循此库的设置说明):

self.appDrawController = drawerController;

In your applicationWillEnterForeground: 在您的应用程序WillEnterForeground中:

THECLASSTHATCONTAINSTHEPINVIEW *yourClass = self.appDrawController.centerViewController.childViewControllers[0];

Now you can access the public methods/properties, so: 现在,您可以访问公共方法/属性,因此:

[[yourClass pinEntryField] becomeFirstResponder];

Does this help at all ? 这有帮助吗?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM