Objective C:如何从 appdelegate 呈现模态视图控制器?

发布于 2024-11-29 09:56:35 字数 608 浏览 3 评论 0原文

我在我的应用程序的 appdelegate 中。如何在“didfinishlaunching”方法中添加模式视图控制器?

我尝试了以下但没有工作

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

编辑: 我将我的实现更改为以下内容

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

我检查了“选定的视图控制器”不为空...但是我仍然无法获得所需的输出。我有什么遗漏的吗?

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]; 

EDIT:
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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

╰沐子 2024-12-06 09:56:35

假设 tabController 和 navigationController 不为 nil,则 applicationDidFinishLaunching 可能太快而无法显示模式视图控制器。

  1. 确保在使窗口成为关键且可见之后放置该代码。 [self.window makeKeyAndVisible];
  2. 如果这不起作用,请尝试侦听该窗口的 UIWindowDidBecomeKeyNotification
  3. 您可以尝试使用 performSelector:withObject:afterDelay:

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

  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:
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文