ios - 从 app delegate 覆盖默认的 Storyboard View Controller

标签 ios uiviewcontroller uistoryboard

对于 IB Storyboard,始终会选择一个默认的 View Controller ,该 Controller 将在应用程序启动时显示。

有什么方法可以在代码中覆盖它吗?例如,我的应用程序委托(delegate)逻辑可能需要将用户发送到其他地方。有这种可能吗?

最佳答案

我将以下所有内容放在默认 Controller 上。

- (void)gotoScreen:(NSString *)theScreen
{
    AppDelegate *app = (AppDelegate *)[[UIApplication sharedApplication] delegate];

    UIViewController *screen = [self.storyboard instantiateViewControllerWithIdentifier:theScreen];
    [app.window setRootViewController:screen];
}

然后在逻辑发生的地方我将根据需要调用以下内容。

if(myBool == YES) {
    [self gotoScreen:@"theIdentifier"];
}

关于ios - 从 app delegate 覆盖默认的 Storyboard View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10569267/

相关文章:

ios - 无法从 iPhone 上的内部服务器安装企业应用程序 ( IOS 11.4)

ios - 垂直对齐 UILabel

ios - 关闭当前 View Controller 回到主视图 Controller 应用程序崩溃 IOS 7

ios - iPhone 5如何切换不同的 Storyboard?

ios - 从不同的 ViewController iOS 更新 UITextField

ios - View 不会像在 Storyboard 中那样出现在 iPhone 上

iphone - 搜索显示 Controller 搜索栏

ios - 不同子类的数组。 UITableView数据

ios - 注销并返回到 rootViewController 的正确方法

幕后的 iOS 横向处理