如何将UIVIewController设置为RootViewController?

时间:2012-02-29 13:39:01

标签: iphone objective-c ios xcode4.2

我想知道如何在不使用UITableView到其根视图控制器的情况下在UINavigationController中设置UIViewController。对此有何帮助?提前谢谢。

4 个答案:

答案 0 :(得分:8)

您可以按照以下方式执行此操作:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // ...
    UIViewController *myViewController = [[UIViewController alloc] init];
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:myViewController];
    self.window.rootViewController = navigationController;
    // ...
}

如果需要,您可以替换myViewController的类和/或使用笔尖对其进行初始化。

答案 1 :(得分:1)

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


   UINavigationController *nav=[[UINavigationController alloc]initWithRootViewController:[[OptionViewController alloc]initWithNibName:@"OptionViewController" bundle:nil]];
    self.window.rootViewController=nav;

    self.window.backgroundColor = [UIColor grayColor];
    [self.window makeKeyAndVisible];
    return YES;
}

答案 2 :(得分:0)

它为我工作:

在窗口上设置tabviewcontroller,然后它就能正常工作。

UIWindow *window = [UIApplication sharedApplication].keyWindow;
        UITabBarController *tabVC = [self.storyboard instantiateViewControllerWithIdentifier:@"MyMainView"];

        [window setRootViewController:tabVC];

答案 3 :(得分:-3)

UINavigationController pushViewController:animated: