Ios UITabBarController视图控制器奇怪的行为

Ios UITabBarController视图控制器奇怪的行为,ios,objective-c,ios7,Ios,Objective C,Ios7,伙计们,我需要你们帮助ObjectiveC和UITabBarController @interface DZCustomTabBarController : UITabBarController @end 我有两段代码具有相同的(我希望)功能。但只适用于第二种情况。任务是动态创建ViewController数组并将其分配给UITabBarController viewControllers属性 我有一个从UITabBarController继承的DZCustomTabBarControlle

伙计们,我需要你们帮助ObjectiveC和UITabBarController

@interface DZCustomTabBarController : UITabBarController

@end
我有两段代码具有相同的(我希望)功能。但只适用于第二种情况。任务是动态创建ViewController数组并将其分配给UITabBarController viewControllers属性

我有一个从UITabBarController继承的DZCustomTabBarController

@interface DZCustomTabBarController : UITabBarController

@end
和property
@property(非原子,强)NSMutableArray*控制器指向我这样动态创建的ViewController

一切都在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];

我在目标C方面没有进步,所以我需要你的帮助。我认为这行代码中的问题
[self.controllers addObject:controller]

我认为,您的
控制器
属性未初始化。尝试执行self.controllers=[NSMutableArray]在使用for in循环之前。祝你好运

我认为,您的
控制器
属性未初始化。尝试执行self.controllers=[NSMutableArray]之前,请先执行代码>操作。祝你好运法赫里·阿齐莫夫,谢谢你,伙计,你真的救了我一天。你应该把答案贴出来,我会把它标记为“解决”。非常感谢:D