目标C:如何从appdelegate呈现模态视图控制器? [英] Objective C: How to present modal view controller from appdelegate?

查看:177
本文介绍了目标C:如何从appdelegate呈现模态视图控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在申请的appdelegate。如何在didfinishlaunching方法中添加模态视图控制器?

I am in the appdelegate of my application. How can I add a modal view controller in the "didfinishlaunching" method?

我尝试了以下但是没有工作

I tried the following but did not work

SomeViewController *vc = [[SomeViewController alloc]init];
[self.tabController.navigationController presentModalViewController:vc animated:NO]; 

编辑:
我将实施改为以下

I changed my implementation to the following

self.tabController.selectedViewController 
= [self.tabController.viewControllers objectAtIndex:0];
SomeViewController *vc = [[SomeViewController alloc]init];
[self.tabController.selectedViewController presentModalViewController:vc animated:NO];

我检查过选定的视图控制器不是空的...但是我还是不能获得我需要的输出。有什么我缺少的吗?

I checked that the 'selected view controller' is not null... however I am still not able to get the output I needed. Is there anything I am missing?

推荐答案

假设tabController和navigationController不是nil,applicationDidFinishLaunching可能太早显示模态视图控制器。

Assuming tabController and navigationController are not nil, the applicationDidFinishLaunching may be too soon to display the modal view controller.


  1. 确保在创建窗口键并显示后放置该代码。 [self.window makeKeyAndVisible];

  2. 如果这不起作用,请尝试侦听 UIWindowDidBecomeKeyNotification 用于该窗口

  3. 您可以尝试使用 performSelector:withObject:afterDelay:

  1. Make sure you put that code after you make the window key and visible. [self.window makeKeyAndVisible];
  2. If that does not work try listening for the UIWindowDidBecomeKeyNotification for that window
  3. You can try delaying presentation of that modal a few seconds using performSelector:withObject:afterDelay:

这篇关于目标C:如何从appdelegate呈现模态视图控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆