Frage

Diese Anwendung ich schreibe hat ein Problem.

Ich gründe den UITabBar in meinem Anwendungsfenster und die Symbole in der Ansicht Dateien eingestellt. Aber wenn ich die App laufen, zeigen die ersten Symbole oben (weil die Ansicht geladen ist glaube ich) und die anderen Symbole zeigen nicht, bis ich darauf klicken.

Muss ich self.tabBarItem in einem anderen Verfahren implementieren nicht viewDidLoad?

Vielen Dank im Voraus an alle!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    tabBar = [[UITabBarController alloc] init];

    SubscriptionsController *subscriptionsController = [[SubscriptionsController alloc] init];
    FavoritesController  *favoritesController  = [[FavoritesController  alloc] init];
    CategoriesController *categoriesController  = [[CategoriesController alloc] init];
    TagsController   *tagsController    = [[TagsController   alloc] init];
    HelpScreenController *helpScreenController  = [[HelpScreenController alloc] init];

    tabBar.viewControllers = [NSArray arrayWithObjects:
        subscriptionsController, 
        favoritesController, 
        categoriesController, 
        tagsController, 
        helpScreenController, 
        nil
        ];

    [window addSubview:tabBar.view];

    // Override point for customization after application launch.
    [window makeKeyAndVisible];
    return YES;
}

//The View

- (void)viewDidLoad {
    [super viewDidLoad];
    tabIcon = [[UITabBarItem alloc] initWithTitle:@"Abonime" image:[UIImage imageNamed:@"subscr.png"] tag:0];
    self.tabBarItem = tabIcon;
    [tabIcon release];
}
War es hilfreich?

Lösung

ich glaube, Sie die tabBarItem Eigenschaft in einem View-Controller setzen sollten ist bestimmte Initialisierung (Beurteilung aus dem Code, muss es -init für jede der Steuerungen sein). In der Tat ist die Tab-Leiste Controller intelligent genug, um die Ansichten bei Bedarf zu laden, die vor, sollte die tabBarItem Eigenschaft festgelegt wird viewDidLoad gesendet wird.

Auch scheinen Sie alle View-Controller undicht werden. Um dies zu beheben, gehen Sie wie folgt vor:

SubscriptionsController *subscriptionsController = [[[SubscriptionsController alloc] init] autorelease];

Andere Tipps

Richtig. Die Symbole zeigen nicht, weil die Aussicht (andere als die ersten, noch nicht geladen ist). Und wird nicht geladen, bis Sie eine Ansicht tippen, weil viewDidLoad erst dann aufgerufen wird.

Entfernen Sie den Code in den einzelnen UIViewControllers viewDidLoad und tun dies ...

NSArray *controllers = [NSArray arrayWithObjects:
                                                [NSDictionary dictionaryWithObjectsAndKeys:@"SubscriptionsController", @"class", [UIImage imageNamed:@"btn_tax.png"], @"icon", @"Abonime", @"title", nil],
                                                [NSDictionary dictionaryWithObjectsAndKeys:@"FavoritesController", @"class", [UIImage imageNamed:@"btn_tax.png"], @"icon", @"Abonime", @"title", nil],
                                                [NSDictionary dictionaryWithObjectsAndKeys:@"CategoriesController", @"class", [UIImage imageNamed:@"btn_tax.png"], @"icon", @"Abonime", @"title", nil],
                                                [NSDictionary dictionaryWithObjectsAndKeys:@"TagsController", @"class", [UIImage imageNamed:@"btn_tax.png"], @"icon", @"Abonime", @"title", nil],
                                                [NSDictionary dictionaryWithObjectsAndKeys:@"HelpScreenController", @"class", [UIImage imageNamed:@"btn_tax.png"], @"icon", @"Abonime", @"title", nil],
                                                nil];

NSMutableArray *controllerArray = [NSMutableArray array] ;

 for (NSUInteger i = 0; i < [controllers count]; i++)
 {
    id newClass = [[NSClassFromString([[controllers objectAtIndex:i] objectForKey:@"class"]) alloc] init];
    UITabBarItem *tabItem = [[UITabBarItem alloc] init];
    tabItem.image = [[controllers objectAtIndex:i] objectForKey:@"icon"];
    tabItem.title = [[controllers objectAtIndex:i] objectForKey:@"title"];
    tabItem.tag = i;
    [(UIViewController*)newClass setTabBarItem:tabItem];
    [tabItem release];
    [controllerArray addObject:newClass];
    [newClass release];
 }

 tabBar.viewControllers = controllerArray;
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top