views:

811

answers:

2

I am following the Iphone UI tab controller tutorial, I basically mimicked the code at the bottom link text

// Create a temporary window object to assign to the window property 
    UIWindow *tempWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen]
 bounds]];
    // Make the window background red so that you can see that the window has been added
    tempWindow.backgroundColor = [UIColor grayColor];
    self.window = tempWindow;
    [tempWindow release];


    // add the tab bar controller
    UITabBarController *tabBarController;
    tabBarController = [[UITabBarController alloc] initWithNibName:nil bundle:nil];


    PhoneContactsView *phoneContactsView = [[[PhoneContactsView alloc] init] autorelease];
    OtherContactsView *otherContactsView = [[[OtherContactsView alloc] init] autorelease];

    //Add all the view to the tabBarView
    tabBarController.viewControllers = [NSArray arrayWithObjects:otherContactsView,phoneContactsView, nil];

    //Add all the button's to the bar

    UITabBarItem *otherContactsTabBarItem = 
    [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemTopRated tag:1];  
    otherContactsBarItem.title = @"My Contacts";
    otherContactsView.tabBarItem = otherContactsBarItem; 
    [otherContactsBarItem release];

    UITabBarItem *phoneContactsBarItem =
    [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemContacts tag:1];  
    phoneContactsView.tabBarItem = phoneContactsBarItem; 
    [phoneContactsBarItem release];

    tabBarController.selectedViewController
    = [tabBarController.viewControllers objectAtIndex:0];

    [window addSubview:tabBarController.view];
    [tabBarController release];
    [window makeKeyAndVisible];

OtherContacts and PhoneContacts are just default empty view, I only changed there background to make sure they were loading. When I run this, The first view loads, but I am unable to click on the Tab Bar to change between the view's am I missing something ?

A: 

If OtherContacts and PhoneContacts are "UIView" classes and not UIViewController classes, that would explain the problems - the tab bar controller needs UIViewController references.

Kendall Helmstetter Gelner
They are both UIViewControllers, they both have a title set also.
daniel
+1  A: 

Found the BUG:

[window addSubview:tabBarController.view];
[tabBarController release]; <------------- I am releasing the tabBarController while still in use 
[window makeKeyAndVisible];

Thats why the tab bar controller was unresponsive. -daniel

daniel