0

I'm getting a really bizarre output from that contructor. It does not actually store any of the objects. I debugged the method and the objects being stored are initialized properly. I use this array to set the vc's on a UITabBarController and the tab bar is empty. Here's the code

-(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];


}

Thanks in advance!

2
  • Yes, it does. Your problem is something else besides "initWithObjects: doesn't work". What is the context for this code? Commented Dec 1, 2010 at 23:34
  • that method gets called on applicationDidFinishLaunching to set the UITabBarController VC array with the NSArray *allFeaturesAvailableTabBarItemArray, which is a private member in the app delegate. Commented Dec 1, 2010 at 23:44

2 Answers 2

1

I think you may be over releasing the tab bar images (FWIW).

Sign up to request clarification or add additional context in comments.

1 Comment

Yes they are. +imageNamed: is an autoreleased object (is neither alloc, new or retain and does not contain copy) and so you must not release the image after adding it to the array.
1

I ended up removing one by one the objects in the array to see which one was causing issues. the first object added was 0x0 (nil) so it didn't add anything to the array. The strange thing is that

on

issuesNavigationController.tabBarItem =issuesTabBarItem;

I'm calling properties on an nil object and fired no alarms. Is this "expected" or is it kind of a bug I should report?

Thank you very much to all of you for your quick answers. I'm going to take care of the overrelease as well Thanks!

1 Comment

Calling properties is just syntactic sugar for calling setters and getters. When you call a property on an object you are sending it a message. Since it's always safe in Objective-C to send a message to a nil this is expected behaviour.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.