【问题标题】:PushViewController does not work when called from App Delegate从 App Delegate 调用时,PushViewController 不起作用
【发布时间】:2012-01-03 17:39:59
【问题描述】:

我有一个基于标签栏的应用程序。当应用程序处于活动状态时,我希望它转到第二个标签栏(SecondViewController),然后打开 DetailViewController。

这是我的做法:

AppDelegate.m

- (void)applicationDidBecomeActive:(UIApplication *)application {
    self.tabBarController.selectedViewController = [self.tabBarController.viewControllers objectAtIndex:1];

    SecondViewController *secondView = [[SecondViewController alloc] init];
    [secondView openDetailView];
    [secondView release];

}

SecondViewController.m

-(void)openDetailView{
     NSLog(@"open detail view");

     DetailViewController *detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
            [[self navigationController] pushViewController:detailViewController animated:YES];
}

openDetailView() 确实运行(因为我看到 nslog 工作),但 DetailView 没有被推送?我知道代码有效,因为我在 IBAction 中有相同的代码,它确实推送了 detailView。该问题与从 AppDelegate(或切换选项卡)调用它有关。

那么,当我从 App Delegate 调用视图时,为什么视图没有被推送?任何帮助是极大的赞赏。

【问题讨论】:

  • 使用以下代码检查您是否正在获取导航控制器的值 - UINavigationController navController = [(MyAppDelegate)[[UIApplication sharedApplication] delegate] navigationController];还要确保您有一些 IBOutlet,然后它们连接正确。
  • [self navigationController] 很可能是 nil,因为 secondViewController 没有分配给任何 navigationController(至少从您向我们展示的代码来看。

标签: iphone ios uitabbarcontroller uiapplicationdelegate pushviewcontroller


【解决方案1】:

您将 detailViewController 推送到 secondView 的 Navigation-Stack,但 secondView 不存在。

试试这个...

SecondViewController *secondView ...

[self.tabBarController pushViewController:secondView animated:YES];  <==

[secondView openDetailView];

【讨论】:

    猜你喜欢
    • 2014-07-24
    • 2013-09-04
    • 2014-09-16
    • 2015-10-14
    • 1970-01-01
    • 2011-07-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多