[英]UITabBarController viewControllers strange behavior
伙計們,我需要ObjectiveC和UITabBarController的幫助。
我有2個具有相同(希望)功能的代碼。 但僅適用於第二個。 該任務是動態創建viewControllers數組並將其分配給UITabBarController viewControllers屬性。
我有從UITabBarController繼承的DZCustomTabBarController。
@interface DZCustomTabBarController : UITabBarController
@end
和屬性@property (nonatomic, strong) NSMutableArray *controllers;
指向我這樣動態創建的viewControllers。
一切都在viewDidLoad方法中發生
下面的代碼不起作用
NSArray *titles = @[@"first", @"second"];
for (NSString *title in titles) {
DZViewController *controller = [[DZViewController alloc] init];
controller.title = title;
[self.controllers addObject:controller];
}
self.viewControllers = self.controllers ;
我不知道為什么。
但是這段代碼有效。
DZViewController *firstViewController = [[DZViewController alloc] init];
firstViewController.title = @"first";
DZViewController *secondViewController = [[DZViewController alloc] init];
secondViewController.title = @"second";
self.viewControllers = @[firstViewController, secondViewController];
我在Objective C方面並不先進,所以需要您的幫助。 我認為這行代碼中的問題[self.controllers addObject:controller];
我認為,您的controllers
屬性未初始化使用。 嘗試做self.controllers = [NSMutableArray array];
在使用准備周期之前。 祝好運!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.