UITabBarController is loading two tabs at application start
I'm developing a multi device App with separate views for iPhone and iPad. Within my App I'm using a UITabBarController with four tabs of content as the mainView.
The first tab contains a UINavigationController the second tab contains a UIViewController. Third tab is like first tab but with other NIB and Class-Files. And fourth tab is like second tab but with other content.In every viewDidLoad Method I wrote something to console like "[currentview] was loaded" and currentview was replaced with an identifying name for the view which was loaded.
If I start my App on iPhone then the console shows me that without any user interactio开发者_运维问答n the first tab and the third tab (both UINavigationController) both were loaded. In detail the third tab was loaded before the first tab. If I start my App in iPad then only the first tab is loaded like it should have to be. Except for implementing NIB files targeted for iPad I use the same source code at the beginning of my App.In AppDelegate_iPhone.m I only add the UITabBarController.view as a subview to window. Same procedure is done in AppDelegate_iPad.m
I already googled about this and found out that calling a controllers.view results in loading the view but programmatically I don't call neither the view of the first tab nor the third tab. This is done by UITabBarController in his natural way (didn't change anything for this controller). So I'm a bit confused why my App loads the third tab on iPhone. Because of this matter I had to remove some code done in viewDidLoad of the third tab because this code only had effect if the tab was nearly about to display.
I hope anybody has had the same issue and could tell me a solution or maybe a hint.
Finally I found my mistake.
Creating a new project with a UITabBarController and four tabs with the given constellation showed up that the error wasn't a general one. After realizing this I went step by step through my MainWindow_[ver].xib comparing the differences between iPhone and iPad version.
I found out that in MainWindow_iPhone.xib the third tab was declared as a UINavigationController. Within this NavigationController I had a UITableViewController whose contents came from a class/nib linked via Interface Builder. Compared with the MainWindow_iPad.xib (where the error didn't occur) I found out that I used a UIViewController within the iPad version instead of UITableViewController.
After changing the iPhone version to UIViewController the error disappeared. Hooray :)
To approve if this error occurs everytime a UITableViewController was used in another tab than the first one I edited the newly created project and changed the third's tab UIViewController (within the UINavigationController) to a UITableViewController. As expected the third tab was loaded before the first tab.
Additional info: although in MainWindow_[ver].xib I declared a UIViewController to be loaded the specific implementation was a UITableViewController subclass. Seems to work because UITableViewController is a subclass of UIViewController but still strange why the superclass has to be specified in the MainWindow_[ver].xib
精彩评论