【问题标题】:rootViewController isn't working (nil?) on the backgroundrootViewController 在后台不工作(零?)
【发布时间】:2016-06-20 14:03:50
【问题描述】:

我正在尝试将一个名为 myVCmyViewController 对象设置为 AppDelegate 上的窗口 rootViewController,如下所示:

-(void)application:(UIApplication *)application handleActionWithIdentifier:(NSString *)identifier forLocalNotification:(UILocalNotification *)notification completionHandler:(void (^)())completionHandler
{
    self.myVC=(myViewController*)self.window.rootViewController;
}

应用程序运行时一切正常,但在后台根本不工作。

有人知道我怎样才能让它在后台也能工作吗?

谢谢!

【问题讨论】:

  • 你的 rootViewController navigationController 或 viewController 是什么?
  • @Pushpa viewController
  • 方法是否被执行,尝试在方法中记录一些内容。
  • 看看这个解决方案:stackoverflow.com/questions/30592521/…
  • @BharatModi 在应用程序运行时执行,我怎么知道它是否在后台执行?

标签: ios objective-c iphone cocoa-touch uiwindow


【解决方案1】:

试试这个

编辑:

AppDelegate.m

-(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"STORYBOARD_NAME" bundle:nil];
ViewController *ViewController = [storyboard instantiateViewControllerWithIdentifier:@"YOUR_IDENTIFIER"];[self.window makeKeyAndVisible];     
[self.window.rootViewController presentViewController:ViewController animated:YES completion:NULL];
return YES;
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
NSLog(@"applicationDidEnterBackground");
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:ADD_YOURCONTROLLER];

[self presentViewController:navController animated:YES completion:nil];
}

希望这会有所帮助。

【讨论】:

  • 我想使用故事板展示 myVC,但我没有导航控制器
  • 试试我的编辑并告诉我
  • 虽然我没有navigationController,但我应该使用navigationController吗?
  • 我回家后会试试看,我会告诉你的。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-08-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多