ios - 关于在应用程序启动结束时有 Root View Controller 的错误消息

标签 ios objective-c cocoa-touch uiviewcontroller

Stack Overlow 上有一些关于此错误的问题,但似乎没有一个解决方案对我有用。有人能看一眼我的代码,看看我为什么会收到以下错误吗?

Applications are expected to have a root view controller at the end of application launch

AppDelegate.m:

#import "AppDelegate.h"
#import "ViewController.h" //import header file

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    UIStoryboard*  sb = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController* viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}

@end

最佳答案

您将 rootViewController 设置为 self.viewController 但您从未设置 self.viewController

试试这个:

self.viewController = [sb instantiateViewControllerWithIdentifier:@"viewController"];
self.window.rootViewController = self.viewController;

关于ios - 关于在应用程序启动结束时有 Root View Controller 的错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23532115/

相关文章:

iphone - facebook iphone sdk 注销问题!

ios - iOS6 上的自动布局问题 : "All dependent constraints should have been removed from the engine and also from the view' s list of dependent constraints"

ios - 在 Swift 中创建 block 不起作用

ios - 让页面 View 在最后一个屏幕上弹出

ios - 键盘来时,如何设置UITextView中的文本字段上下移动?

objective-c - 变量声明中const关键字定位的意义

ios - 在 Swift 中,如何翻转 UITableViewCell?

iphone - 如何从 UIView 访问 UIViewController 的按钮?

iphone - 是drawRect : called on multiple threads when using a CATiledlayer?

objective-c - 如何使用带参数的事件处理程序?