iOS 以编程方式更改 AppDelegate 中的 View

标签 ios uinavigationcontroller uitabbarcontroller appdelegate

我正在尝试在收到特定推送通知时更改 View ,但收效甚微。 (使用带有推送通知的解析,满足应用程序打开和关闭的时间)。

我的 Storyboard 看起来像这样,我正在尝试将 AppDelegate 中的 View 更改为 DetailViewController。 enter image description here

现在我可以通过更改根 Controller 来更改 View ,但我只能附加我的选项卡 View 或导航,而不能同时附加两者。

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    DetailViewController *detail = (DetailViewController *)[mainStoryboard instantiateViewControllerWithIdentifier:@"detail"];
    [detail setDetailItem:StreamData[2]];

    self.window.rootViewController = detail;

当然,(下文)的使用仅适用于其他 Controller 。

[self.navigationController pushViewController:detail animated:YES];

我想知道这是否可以通过 AppDelegate 实现,同时保持底部的标签栏和顶部的导航?

我最初的工作是将 AppDelegate 的触发器设置为可从所有 Controller 访问的全局变量,然后使用 viewDidAppear 之类的东西来检查它们的 View 是否需要更改。虽然这似乎太耗费资源,但它保持了我的布局。

我的问题与此类似:pushing view controller inside a tab bar from app delegate, after a notification

最佳答案

我已经解决了您的问题。创建了一些场景,不确定它是否适用于您的情况。无论如何尝试一下

我的 Storyboard

enter image description here

我做了什么

 UIStoryboard *mainStoryboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];

[(UITabBarController *)self.window.rootViewController setSelectedIndex:1];
UINavigationController *nav = [[(UITabBarController *)self.window.rootViewController viewControllers]objectAtIndex:1];
UIViewController *detail = [mainStoryboard instantiateViewControllerWithIdentifier:@"detail"];
[nav pushViewController:detail animated:NO];

这给了我带有按钮的详细 View Controller 作为第一个带有标签栏和导航 Controller 的 View

关于iOS 以编程方式更改 AppDelegate 中的 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16729259/

相关文章:

ios - Segue 导致 UITabBarController 在 Swift 中向上移动状态栏?

iphone - 为 iPhone UITabBar 生成图标

ios - 如何检测哪个 segue 标识符激活了当前 View Controller

ios - 卡住!只能给presentviewcontroller传数据,不能传pushviewcontroller

iphone - 动画 UInavigationBar 离屏留下黑色矩形

objective-c - 在 UINavigation 后退按钮旁边添加一个 UIBarButtonItem

ios - 在 UITabBar 中启动 Storyboard View

iphone - 如何正确地向用户提供网络反馈?

ios - 如何在 MPMoviePlayerController 中获取视频的真实大小?

ios - Xcode将新文件添加到SVN中的现有项目