iPhone - 按下控制器并同时切换选项卡

发布于 2024-12-01 00:06:50 字数 483 浏览 2 评论 0原文

在常见的 iPhone 配置中,我的应用程序的主窗口是一个包含多个 UINavigationController 的选项卡栏控制器。我现在的绊脚石是同时推动和更改控制器:看来我可以按顺序执行这两项操作,但我必须再次按选项卡才能更新视图。

例如,我在选项卡 1 上,有一个按钮可以在选项卡 2 上加载我想要立即呈现的新视图。代码是

tabController.selectedViewController = myListsController;
EditListViewController * editController = [[EditListViewController alloc] initWithList:l];
[myListsController.navigationController pushViewController:editController animated:YES];

使用此代码,会显示新选项卡,但我没有看到新视图。这可以做到吗?

In a common iPhone configuration, my application's main window is a tab bar controller that contains multiple UINavigationController. My stumbling block now is pushing and changing controllers simultaneously: it appears that I can do both sequentially, but I have to press the tab again to have the view updated.

For example, I'm on tab 1, and I have a button that will load a new view on tab 2 that I want to present right away. Code for that is

tabController.selectedViewController = myListsController;
EditListViewController * editController = [[EditListViewController alloc] initWithList:l];
[myListsController.navigationController pushViewController:editController animated:YES];

With this code, the new tab is presented, but I don't see the new view. Can this be done?

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

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

发布评论

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

评论(2

余生一个溪 2024-12-08 00:06:50

如果您只有 2 个选项卡视图(并且 myListsController.navigationController 是第二个选项卡的根),您可以这样做:

UINavigationController *nc = myListsController.navigationController;
EditListViewController *editController = [[EditListViewController alloc] initWithList:l];
[myListsController.navigationController setViewControllers:
    [NSArray arrayWithObjects:[[nc viewControllers] objectAtIndex:0],editController,nil]];

NSMutableArray *vcs = [[tabController viewControllers] mutableCopy];
[vcs replaceObjectAtIndex:1 withObject:nc];
[tabController setViewControllers:vcs];
[vcs release];
[self.tabController setSelectedIndex:1];

If you have only 2 tab views (and myListsController.navigationController is the root of your 2nd tab), you could do it like this:

UINavigationController *nc = myListsController.navigationController;
EditListViewController *editController = [[EditListViewController alloc] initWithList:l];
[myListsController.navigationController setViewControllers:
    [NSArray arrayWithObjects:[[nc viewControllers] objectAtIndex:0],editController,nil]];

NSMutableArray *vcs = [[tabController viewControllers] mutableCopy];
[vcs replaceObjectAtIndex:1 withObject:nc];
[tabController setViewControllers:vcs];
[vcs release];
[self.tabController setSelectedIndex:1];
离线来电— 2024-12-08 00:06:50

尝试一下。

-(void)viewWillAppear:(BOOL)animated {
//your code
}

在 Viewcontroller 类中

Try

-(void)viewWillAppear:(BOOL)animated {
//your code
}

in you Viewcontroller class.

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