在 appDelegate 中使用导航对 TabBarController 进行编程 [英] Programming TabBarController with Navigation in appDelegate

查看:23
本文介绍了在 appDelegate 中使用导航对 TabBarController 进行编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 tabbarcontroller 的第三个选项卡中包含一个导航控制器.我收到了一些反馈,但只能做到这一点.下面的代码不会产生任何错误,但在应用程序刚刚退出时似乎不起作用.有没有人对我可能做错的事情有任何意见?

I am trying to include a navigation controller within the third tab of my tabbarcontroller. I have had some feedback but am only able to get about this far. The code below doesn't produce any errors, but does not seem to work as the app just quits out. Does anyone have any input on what I might be doing wrong?

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

它对我有用

这篇关于在 appDelegate 中使用导航对 TabBarController 进行编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆