从 App Delegate 调用时 PushViewController 不起作用

发布于 2024-12-25 02:14:06 字数 1056 浏览 1 评论 0原文

我有一个基于标签栏的应用程序。当应用程序变为活动状态时,我希望它转到第二个选项卡栏 (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 中具有相同的代码,它确实推送了详细视图。该问题与从 AppDelegate (或切换选项卡)调用它有关。

那么,当我从应用程序委托调用视图时,为什么视图没有被推送呢?非常感谢任何帮助。

I have a tab-bar based app. When the app becomes active, I want it to go to the second tab bar (SecondViewController) and then, open DetailViewController.

Here's how I'm doing it:

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() does run (as I see the nslog working), but the DetailView does not get pushed? I know the code works because I have identical code in an IBAction which DOES push the detailView. The problem has something to do with it being called from the AppDelegate (or switching tabs).

So why doesn't the view get pushed when I call it from the App Delegate? Any help is greatly appreciated.

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

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

发布评论

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

评论(1

苍风燃霜 2025-01-01 02:14:06

您将detailViewController推送到secondView的导航堆栈,但secondView却无处可去。

试试这个...

SecondViewController *secondView ...

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

[secondView openDetailView];

You push detailViewController to the Navigation-Stack of secondView, but secondView is in nowhere.

Try this...

SecondViewController *secondView ...

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

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