Ich habe einen UITabBarController, der programmatisch erstellt wird, der 4 Unterklassen von UIViewController verwaltet. Etwas wie:Wie kann UITabBarController View Controller träge laden?
//Create Controller 1
self.terminal = [[[TerminalController alloc] initWithNibName:@"TerminalView" bundle:nil] autorelease];
UINavigationController* navTerminal = [[[UINavigationController alloc] initWithRootViewController:terminal] autorelease];
navTerminal.title = __(@"Terminal");
navTerminal.navigationBar.barStyle = UIBarStyleBlackOpaque;
navTerminal.tabBarItem.image = [UIImage imageNamed:@"tab_terminal.png"];
//Create Controller 2
self.history = [[[HistoryController alloc] initWithNibName:@"HistoryView" bundle:nil] autorelease];
UINavigationController* navHistory = [[[UINavigationController alloc] initWithRootViewController:history] autorelease];
navHistory.title = __(@"History");
navHistory.navigationBar.barStyle = UIBarStyleBlackOpaque;
navHistory.tabBarItem.image = [UIImage imageNamed:@"tab_history.png"];
//Create Controller 3
self.settings = [[[SettingsController alloc] initWithNibName:@"SettingsView" bundle:nil] autorelease];
UINavigationController* navSettings = [[[UINavigationController alloc] initWithRootViewController:settings] autorelease];
navSettings.title = __(@"Settings");
navSettings.navigationBar.barStyle = UIBarStyleBlackOpaque;
navSettings.tabBarItem.image = [UIImage imageNamed:@"tab_settings.png"];
//Create Controller 4
HelpController* help = [[[HelpController alloc] initWithNibName:@"HelpView" bundle:nil] autorelease];
UINavigationController* navHelp = [[[UINavigationController alloc] initWithRootViewController:help] autorelease];
navHelp.title = __(@"Help");
navHelp.navigationBar.barStyle = UIBarStyleBlackOpaque;
navHelp.tabBarItem.image = [UIImage imageNamed:@"tab_help.png"];
//Create Tab Bar an add it's view to window.
self.tabBar = [[[UITabBarController alloc] initWithNibName:nil bundle:nil] autorelease];
tabBar.viewControllers = [[[NSArray alloc] initWithObjects:navTerminal, navHistory, navSettings, navHelp, nil] autorelease];
tabBar.delegate = self;
[window addSubview:tabBar.view];
Gibt es eine Möglichkeit, die UITabBarController zu sagen lazily die Ansicht-Controller zu laden? ej, wenn der Benutzer auf eines der Registerkartenelemente klickt oder wenn tabBarController setSelectedIndex aufgerufen wird?
Ich hatte das gleiche Problem wie das OP und dieser Code funktionierte perfekt für mich. Vielen Dank!! Ich konnte die Startzeit meiner App um 2 Sekunden reduzieren. –
Eigentlich mache ich noch etwas mehr Arbeit und teste damit und bin auf ein Problem gestoßen. Wenn ich einen Modal View Controller präsentiere und dieses Modal dann verwerfe, wenn ich zurück zum Tab Controller komme, ist seine Oberfläche total durcheinander. Meine UITabBar wurde verschoben, die UIView, die die Unteransicht des benutzerdefinierten Tab-Controllers ist, wurde erweitert, um mehr von dem Bildschirm zu füllen. Sind Sie auf solche Probleme gestoßen und haben Sie eine Lösung gefunden? –
@Kenny Wyland, ich hatte keine Probleme wie diese, aber ich glaube nicht, dass ich jemals versucht habe, eine modale Ansicht darüber anzuzeigen. Ich kann mir keinen Grund vorstellen, dass es sich so benehmen würde. – zpasternack