我想包括我tabbarcontroller的第三个选项卡内的导航控制器。 我有一些意见,但我只能得到这个远。 下面的代码不会产生任何错误,但似乎并没有工作,因为该应用程序只是退出了。 有没有人有什么我可能是做错了任何输入?
UIViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:@"PDCFirstViewController" bundle:nil];
UIViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:@"SecondViewController" bundle:nil];
viewController3 = [[UIViewController alloc] initWithNibName:@"ThirdViewController"
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
谢谢你们!
int main(int argc, char *argv[])
{
@autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([PDCAppDelegate class]));
}
}
请确保您所使用的所有笔尖的名字,并与类名,也就是说,如果你的类的UIViewController的名字是FirstViewController,笔尖的名称应该是相同的。 你曾用“PDCFirstViewController”为笔尖名。 同样的,ThirdViewController&SecondViewController。
试试下面的代码...
FirstViewController *viewController1 = [[FirstViewController alloc]
initWithNibName:@"FirstViewController" bundle:nil];
SecondViewController *viewController2 = [[SecondViewController alloc]
initWithNibName:@"SecondViewController" bundle:nil];
ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController"
bundle:nil];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];
self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
下面是解
UIViewController *courseView = [[[CoursesView alloc] initWithNibName:@"CoursesView" bundle:nil] autorelease];
UIViewController *subjectViewController = [[[SubjectViewController alloc] initWithNibName:@"SubjectViewController" bundle:nil] autorelease];
UIViewController *videoViewController = [[[VideoViewController alloc] initWithNibName:@"VideoViewController" bundle:nil] autorelease];
UIViewController *quizViewController = [[[QuizViewController alloc] initWithNibName:@"QuizViewController" bundle:nil] autorelease];
UIViewController *proifileViewController = [[[Profile2ViewController alloc] initWithNibName:@"Profile2ViewController" bundle:nil] autorelease];
UINavigationController *coursNav = [[UINavigationController alloc] initWithRootViewController:courseView];
UINavigationController *subjectNav = [[UINavigationController alloc] initWithRootViewController:subjectViewController];
UINavigationController *videoNav = [[UINavigationController alloc] initWithRootViewController:videoViewController];
UINavigationController *quizNav = [[UINavigationController alloc] initWithRootViewController:quizViewController];
UINavigationController *profileNav = [[UINavigationController alloc] initWithRootViewController:proifileViewController];
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[coursNav, subjectNav,videoNav,quizNav,profileNav];
self.tabBarController.navigationController.navigationBarHidden=YES;
self.tabBarController.delegate=self;
[self.window addSubview:self.tabBarController.view];
[self.window makeKeyAndVisible];
这个对我有用