2009-07-08 5 views
0

Je suivais le tutoriel contrôleur onglet interface Iphone, j'imité essentiellement le code en bas link textUITabController développement iphone

// 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 et PhoneContacts sont par défaut juste vue vide, je ne changé il fond pour vous assurer ils chargeaient. Lorsque j'exécute ceci, la première vue se charge, mais je suis incapable de cliquer sur la barre d'onglets pour changer entre les vues et si quelque chose me manque?

Répondre

1

trouvé le BUG:

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

C'est pourquoi le contrôleur de barre d'onglets ne répondait pas. -daniel

0

Si OtherContacts et PhoneContacts sont des classes "UIView" et non des classes UIViewController, cela expliquerait les problèmes - le contrôleur de la barre d'onglets a besoin de références UIViewController.

+0

Ils sont tous les deux UIViewControllers, ils ont tous les deux un jeu de titres. – daniel

Questions connexes