更改实例化的ViewController

时间:2016-10-08 18:34:20

标签: objective-c xcode

我在Xcode中创建了项目,并删除了默认" ViewController"故事板中的类和默认视图。然后我将新的视图控制器放在故事板和表视图中,并创建了名为" StartsController"的新类。此时无法运行我的应用程序,因为它返回通信:

"-[UITableViewController loadView] instantiated view controller with identifier "UIViewController-BYZ-38-t0r" from storyboard "Main", but didn't get a UITableView".

如何选择我的" StartsController"要实例化控制器然后我会正确运行我的应用程序?

1 个答案:

答案 0 :(得分:0)

确保勾选了is initial ViewController is initial ViewController

如果您想以编程方式执行此操作,只需将此代码放入AppDelegate.m中的application:didFinishLaunchingWithOptions:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:UIScreen.mainScreen.bounds];

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

    StartsController *viewController =  ....;

    self.window.rootViewController = viewController;
    [self.window makeKeyAndVisible];

    return YES;
}