0

我试图在我的 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]));
}
}
4

2 回答 2

0

这是解决方案

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];

这个对我有用

于 2012-12-12T12:31:33.083 回答
0

确保您使用的所有 nib 名称以及类名称,即如果您的 UIViewController 的类名称是 FirstViewController,则 nib 名称应该相同。您已经使用“PDCFirstViewController”作为笔尖名称。与 ThirdViewController 和 SecondViewController 相同。

试试下面的代码...

FirstViewController *viewController1 = [[FirstViewController 分配]
initWithNibName:@"FirstViewController" bundle:nil];

SecondViewController *viewController2 = [[SecondViewController 分配]
initWithNibName:@"SecondViewController" bundle:nil];

ThirdViewController *viewController3 = [[ThirdViewController alloc] initWithNibName:@"ThirdViewController"
捆绑:无];
UINavigationController *navigationcontroller = [[UINavigationController alloc]
initWithRootViewController:viewController3];

self.tabBarController = [[UITabBarController alloc] init];
self.tabBarController.viewControllers = [NSArray
arrayWithObjects:viewController1,viewController2,navigationcontroller, nil];
于 2012-12-12T08:44:10.810 回答