上代码了。
        blueViewController = [[BlueViewController alloc] init];
yellowViewController = [[YellowViewController alloc] init];
NSMutableArray *viewControllerArray = [NSMutableArray arrayWithCapacity:3];
[viewControllerArray addObject:blueViewController];
[viewControllerArray addObject:yellowViewController];
tabBar.viewControllers = viewControllerArray;
[self.view addSubview:tabBar.view];
为什么我用NSMutableArray程序就莫名其妙的退出了?而且控制台也没有报任何错误。
换成NSArray *viewControllerArray = [NSArray arrayWithObjects:blueViewController,yellowViewController,nil];就完全正确。
NSMutableArray不是NSArray的子类么?从面向对象继承的角度看,是没有任何问题的呀!为什么程序中止了?还不报错。。

解决方案 »

  1.   

    我给你看个实例吧- (void) setController
    {
    NSMutableArray *controllerArray = [[NSMutableArray alloc] init];
    UINavigationController *navigationController;
    ConfigurationManagement* configurationManagement = [[ConfigurationManagement alloc] init];
    navigationController = [self setUINavigationController:configurationManagement 
       withTag:0 
       withImageName:@"setting.png"
       withTabBarTitle:ConfigurationManagementString];
    [controllerArray addObject:navigationController];
    [navigationController release];

    Conferencing* conferencing = [[Conferencing alloc] init];
    navigationController = [self setUINavigationController:conferencing 
       withTag:1 
     withImageName:@"meeting.png"
       withTabBarTitle:MultMeetingString];
    [controllerArray addObject:navigationController];
    [navigationController release];

    ProvisionalMeeting *provisionalMeeting = [[ProvisionalMeeting alloc] initWithNibName:@"ProvisionalMeeting" bundle:nil];
    navigationController = [self setUINavigationController:provisionalMeeting 
       withTag:2
     withImageName:@"tmpcall.png"
       withTabBarTitle:ProvisionalMeetingString];
    [controllerArray addObject:navigationController];
    [navigationController release];

    CallRecords *callRecord = [[CallRecords alloc] init];
    navigationController = [self setUINavigationController:callRecord 
       withTag:3 
     withImageName:@"callhistory.png"
       withTabBarTitle:CallRecordsString];
    [controllerArray addObject:navigationController];
    [navigationController release];

        tabBarController = [[UITabBarController alloc] init];
    [tabBarController setViewControllers:controllerArray animated:NO];
    [window addSubview:tabBarController.view];

    [configurationManagement release];
    [conferencing release];
    [provisionalMeeting release];
    [callRecord release];
    [controllerArray release];

    }
      

  2.   

    你要记住一点,alloc了的东西,一定要release,
    你在[self.view addSubview:tabBar.view];后面,把所有该release的对方都叫上release,
    你的方式,就是面向对象的理论也是错的,因为对象一定要有回收的,而java,C#有自动回收你可以不管,但是Objective - c是没有的自动回收机制的,
      

  3.   


    现在不是内存回收的问题,“你的方式,就是面向对象的理论也是错的,因为对象一定要有回收的,”请问你从哪本书里看到的??我就奇怪了,你自己懂不懂什么叫面向对象啊??它只是一种思想,与对象回不回收有屁关系啊。自己读think in c++去。
      

  4.   

    LZ提的好呀
    c++  是可以的,为什么object c 不行,求答案