Szukałem programowego dodawania paska kart do kontrolera widoku, ponieważ widok przewijania nie mogę go włączyć, nie będąc w środku mojego widoku. Nie jestem zdezorientowany, jak to dodać. Czy trzeba zainicjować moją metodę ViewDidLoad
lub moją AppDelegate
? Jeśli mam:Programowe tworzenie paska zakładek dla ViewController
UITabBarController *tabBar = [[UITabBarController alloc] init];
[self.view addSubview:tabBar.view];
[tabBar release];
Jak mogę przydzielić go do głębi scrollview
?
Dzięki!
Teraz w mojej klasie appDelegate:
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
UITabBarController *tabBarController = [[UITabBarController alloc] init];
ViewController* vc = [[ViewController alloc] init];
NSArray* controllers = [NSArray arrayWithObjects:vc, tabBarController, nil];
tabBarController.viewControllers = controllers;
[_window addSubview:tabBarController.view];
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
To upaść i nie wiem, czy to uwolnienie mi brakuje.
Edit: dla nikogo innego zastanawiać to w Appdelegate.m:
self.tabBarController = [[[UITabBarController alloc] init] autorelease];
self.tabBarController.viewControllers = @[viewController1, viewController2, viewController3, viewController4];
'Kontrolery NSArray * = [NSArray arrayWithObjects: vc, tabBarController, nil];' Dlaczego dodajesz 'tabBarController'? – Bhavin
Tak, dodałem Edytuj w moim pytaniu, aby pokazać, co zadziałało. –
Było jeszcze jedno i było: Dodałeś 'tabBarController' w tablicy' viewControllers' i to było złe. Właśnie to dodałem w mojej odpowiedzi. – Bhavin