每次我的应用程序激活时,我都试图呈现一个 View Controller (密码请求类型 View )。输入正确的密码后,它应该从堆栈中弹出。我尝试推送的密码 View 不是初始 View Controller ,因此我无法从 AppDelegate 的 applicationDidBecomeActive 访问它。
我还尝试从我的 MainViewController 的 ViewWillAppear 推送密码 View ,但是当应用程序激活时它不会被调用;仅当屏幕刷新时。
过去几天我一直在研究 SO 中的类似问题,但我仍然不了解正确的方法。我听说我可能无法以这种方式推送 View ,因为 applicationDidBecomeActive 可能会在 Storyboard 或 NavigationController 连接/初始化/等之前被调用。
如果有人可以为我提供推送/呈现 View 的正确方法,或者如果有其他地方可以更好地执行此类操作,我将不胜感激。
已解决:我只是从 Storyboard 中删除了 View 并改用 Nib 。我用过:
PasscodeUnlockVC *passcodeUnlock = [[PasscodeUnlockVC alloc] initWithNibName:@"PasscodeUnlockVC" bundle:[NSBundle mainBundle]];
[(UINavigationController *)self.window.rootViewController pushViewController:passcodeUnlock animated:NO];
查看层级数据:
(gdb) po [[(id)UIApp keyWindow] recursiveDescription]
<UIWindow: 0x736a4b0; frame = (0 0; 320 480); layer = <UIWindowLayer: 0x7367b40>>
| <UILayoutContainerView: 0x76977a0; frame = (0 0; 320 480); autoresize = W+H; layer = <CALayer: 0x769de60>>
| | <UINavigationTransitionView: 0x7692110; frame = (0 0; 320 480); clipsToBounds = YES; autoresize = W+H; layer = <CALayer: 0x769a8c0>>
| | | <UIViewControllerWrapperView: 0x73868d0; frame = (0 64; 320 416); autoresize = W+H; layer = <CALayer: 0x75510e0>>
| | | | <UIView: 0x76b93e0; frame = (0 0; 320 416); autoresize = W+H; layer = <CALayer: 0x7386850>>
| | <UINavigationBar: 0x73664b0; frame = (0 20; 320 44); clipsToBounds = YES; opaque = NO; autoresize = W; layer = <CALayer: 0x7366550>>
| | | <UINavigationBarBackground: 0x7360ea0; frame = (0 0; 320 44); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7366520>> - (null)
| | | <UINavigationItemView: 0x76b95e0; frame = (160 21; 0 0); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x76aa8e0>>
| | | <UINavigationItemButtonView: 0x7550650; frame = (5 7; 73 30); opaque = NO; userInteractionEnabled = NO; layer = <CALayer: 0x7368b40>>
Current language: auto; currently objective-c
(gdb)
最佳答案
我建议您使用 applicationWillEnterForeground:
,而不是 applicationDidBecomeActive:
,因为它更适合多任务手势。例如,如果用户双击主页按钮显示任务栏,然后在不更改应用程序的情况下关闭任务栏,您不希望设置锁定屏幕。
假设您的 AppDelegate
有一个 window
属性,并且您知道窗口的 Root View Controller 是一个 UINavigationController
。
- (void)applicationWillEnterForeground:(UIApplication *)application {
PasscodeViewController *pvc = [[PasscodeViewController alloc] init];
[(UINavigationController *)self.window.rootViewController pushViewController:pvc animated:NO];
// [pvc release]; if not using ARC
}
关于iphone - 从 AppDelegate 呈现特定的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9548911/