0

我想包括一個導航控制器在我的tabbarcontroller的第三個選項卡。我有一些反饋,但只能得到這一點。下面的代碼不會產生任何錯誤,但似乎不起作用,因爲應用程序剛剛退出。有沒有人對我可能做錯了什麼有什麼意見?編程TabBarController與導航在appDelegate

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])); 
} 
} 
+0

據我所知,看起來好爲止。 –

+0

您究竟在哪裏得到這次事故? crashlog是什麼樣的? –

+0

@HermannKlecker,當應用程序啓動時我收到了崩潰。我已更新我的問題以顯示錯誤。 – Brandon

回答

0

確保與所有正在使用的筆尖的名字,並與類名,即 如果類的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]; 
+0

嗨,感謝您的輸入,但我仍然遇到同樣的問題 – Brandon

+0

您是否檢查過所有的nib名稱和已定義的控制器類?並確保你已經在xibs中設置了IBOutlet。 –

+0

確定後,您的建議我不再有崩潰,但我只是看到應用程序加載時,一個空白的黑屏。有任何想法嗎? – Brandon

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

它爲我工作