NSArray -initWithObjects:不存储对象

时间:2010-12-01 23:27:53

标签: objective-c nsarray

我从这个构造函数中得到了一个非常奇怪的输出。它实际上并不存储任何对象。我调试了方法,正确初始化了存储的对象。 我使用这个数组在UITabBarController上设置vc,标签栏为空。这是代码

-(void)initBarItemsWithAllFeatures {

    /*
     Issues 
     */


    UIImage *issuesImage = [UIImage imageNamed:@"issues_on.png"];


    UITabBarItem *issuesTabBarItem = [[UITabBarItem alloc]initWithTitle:NSLocalizedString(@"IssuesTabBarTitle",@"") image:issuesImage tag:0];

    [issuesImage release];

    issuesNavigationController.tabBarItem =issuesTabBarItem;

    [issuesTabBarItem release];
    /*
     thumbs
     */

    ThumbsViewController *thumbsViewController =  [[ThumbsViewController alloc]initWithNibName:@"ThumbsViewController" bundle:nil];


    UIImage *thumbsImage = [UIImage imageNamed:@"thumbs_on.png"];

    UITabBarItem *thumbsTabBarItem = [[UITabBarItem alloc]initWithTitle:NSLocalizedString(@"ThumbsTabBarTitle",@"") image:thumbsImage tag:1];

    [thumbsImage release];

    thumbsViewController.tabBarItem = thumbsTabBarItem;

    [thumbsTabBarItem release];


    /*
     contents
     */

    ContentsViewController *contentsViewController = [[ContentsViewController alloc]initWithNibName:@"ContentsViewController" bundle:nil];

    UIImage *contentsImage = [UIImage imageNamed:@"contents_on.png"];

    UITabBarItem *contentsTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"ContentsTabBarTitle",@"") image:contentsImage tag:2];

    [contentsImage release];

    contentsViewController.tabBarItem = contentsTabBarItem;

    [contentsTabBarItem release];


    /*
     search
     */

    SearchViewController *searchViewController = [[SearchViewController alloc]initWithNibName:@"SearchViewController" bundle:nil];

    UIImage *searchImage = [UIImage imageNamed:@"search_on.png"];

    UITabBarItem *searchTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"SearchTabBarTitle",@"") image:searchImage tag:3];

    [searchImage release];

    searchViewController.tabBarItem = searchTabBarItem;

    [searchTabBarItem release];


    /*
     favourites
     */

    FavouritesViewController *favouritesViewController = [[FavouritesViewController alloc]initWithNibName:@"FavouritesViewController" bundle:nil];

    UIImage *favouritesImage = [UIImage imageNamed:@"favourites_on.png"];

    UITabBarItem *favouritesTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"FavouritesTabBarTitle",@"") image:contentsImage tag:4];

    [favouritesImage release];

    favouritesViewController.tabBarItem = favouritesTabBarItem;

    [favouritesTabBarItem release];

    /*
     contact
     */

    ContactViewController * contactViewController = [[ContactViewController alloc] initWithNibName:@"ContactViewController" bundle:nil];

    UIImage *contactImage = [UIImage imageNamed:@"contact_on.png"];

    UITabBarItem *contactTabBarItem = [[UITabBarItem alloc] initWithTitle:NSLocalizedString (@"contactTabBarTitle",@"") image:contactImage tag:5];

    [contactImage release];

    contactViewController.tabBarItem = contactTabBarItem;

    [contactTabBarItem release];



    /*

     add to an array

     */

    allFeaturesAvailableTabBarItemArray = [[NSArray alloc] initWithObjects:
                                          issuesNavigationController,
                                          thumbsViewController,
                                          contentsViewController,
                                          searchViewController,
                                          favouritesViewController,
                                          contactViewController, nil];


    /*
     release objects
     */

    [thumbsViewController release];
    [contentsViewController release];
    [searchViewController release];
    [favouritesViewController release];
    [contactViewController release];


}

提前致谢!

2 个答案:

答案 0 :(得分:1)

我认为您可能过度发布标签栏图像(FWIW)。

答案 1 :(得分:1)

我最终逐个删除了数组中的对象,以查看哪一个导致了问题。添加的第一个对象是0x0(nil),因此它没有向数组添加任何内容。奇怪的是那个

on

issuesNavigationController.tabBarItem =issuesTabBarItem;

我在nil对象上调用属性并且没有触发警报。这是“预期的”还是我应该报告的一种错误?

非常感谢大家的快速解答。 我还要照顾过度发布,谢谢!