故事板中的自定义导航控制器

时间:2015-04-19 05:38:49

标签: ios objective-c xcode-storyboard

在此我正在创建自定义导航控制器,我有视图作为故事板,但该视图未加载

 self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

//create the navigation controller and add the controllers view to the window
_navigationController = [[UINavigationController alloc] init];
[self.window addSubview:[self.navigationController view]];

//check if the first viewcontroller eixsts, otherwise create it
if(self.firstViewController == nil)
{
    ViewController *firstView = (ViewController *)[mainStoryBoard instantiateViewControllerWithIdentifier:@"mainView123"];
   // ViewController *firstView = [[ViewController alloc] init];
    self.firstViewController = firstView;
}

//push the first viewcontroller into the navigation view controller stack
[self.navigationController pushViewController:self.firstViewController animated:YES];

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];

1 个答案:

答案 0 :(得分:0)

你应该将你的导航设置为rootviewcontroller然后尝试这样的事情。

 UIStoryboard *storyboard =[UIStoryboardstoryboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    MyNewViewController *myVC = (MyNewViewController *)[storyboard    instantiateViewControllerWithIdentifier:@"myViewCont"];
     self.firstViewController = myVc;