在本地通知后呈现 UIViewController
在 application:didFinishLaunchingWithOptions:
中,我初始化了 UINavigationController
。后来,我将 UINavigationController
添加到窗口:
[self.window addSubview:navigationController.view]
这一切都工作正常。现在,我向我的应用程序添加了本地通知,当用户响应通知时,我想呈现一个 UIViewController。所以我想我可以覆盖 application:didReceiveLocalNotification:
并在那里使用我的 navigationController
:
[navigationController pushViewController:someVC animated:YES];
但是,这不起作用。我做了一些调试,注意到虽然 navigationController
不是 nil
,但 navigationController.view
没有超级视图,所以我认为它没有被显示。
所以,我的问题是:我应该将 UIViewController 推送到哪里才能显示?
In application:didFinishLaunchingWithOptions:
I initialize a UINavigationController
. Later, I add the UINavigationController
to the window:
[self.window addSubview:navigationController.view]
This all works fine. Now I added local notifications to my app and when the user responds to one, I would like to present a UIViewController
. So I thought I could override application:didReceiveLocalNotification:
and in there, use my navigationController
:
[navigationController pushViewController:someVC animated:YES];
However, this does not work. I did some debugging and noticed that while navigationController
is not nil
, navigationController.view
has no superview, so I assume it is not being displayed.
So, my question is: where should I push my UIViewController
so that it gets displayed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在您的 AppDelegate.h 中添加以下内容:
在您的 AppDelegate.m 中添加以下内容:
在您的 AppDelegate.m 中的
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification;
方法添加以下内容:确保您的 viewController 是 navigationController
如果不是,请执行以下操作 -- 将这段代码添加到您的
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
:现在 -- 在你的 viewController.m 中将其添加到你的 -viewDidLoad 函数中
创建一个 -(void) localAction 并在该方法中添加你的 navigationController 代码以推送到下一个查看控制器!
希望这对你有用。对我来说就像一个魅力
In your AppDelegate.h add this:
In your AppDelegate.m add this:
In your AppDelegate.m in the
- (void)application:(UIApplication *)app didReceiveLocalNotification:(UILocalNotification *)localNotification;
method add this:Make sure that your viewController is a navigationController
If it's not, do the following -- Add this piece of code to your
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
:Now -- in your viewController.m add this to your -viewDidLoad function
Make a -(void) localAction and in that method add your navigationController code to push to the next View Controller!
Hope that works for you. Works like a charm for me
这就是另一个采用不同方法的解决方案。它对我来说就像一种魅力。一探究竟:
So here it is, another solution with a different approach. It worked like a charm for me. check it out: