uitabbaritems uitabbarのshowアプリケーションが起動したときではなくアイテムをクリックした後
-
08-10-2019 - |
質問
私が書いているこのアプリケーションには問題があります。
私はセットアップしています UITabBar
アプリケーションウィンドウで、ビューファイルにアイコンを設定します。しかし、アプリを実行すると、最初のアイコンが表示されます(ビューがロードされているため)、他のアイコンはクリックするまで表示されません。
実装する必要がありますか self.tabBarItem
他のいくつかの方法ではありません viewDidLoad
?
皆さんによろしくお願いします!
- (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];
}
解決
TabbaritemプロパティをView Controllerの指定された初期イザーに設定する必要があると思います(コードから判断すると、 -init
各コントローラーの場合)。実際、タブバーコントローラーは、オンデマンドでビューをロードするのに十分なほどスマートです。つまり、Tabbaritemプロパティを前に設定する必要があります viewDidLoad
送信されます。
また、すべてのビューコントローラーを漏らしているようです。それを修正するには、次のことを行います。
SubscriptionsController *subscriptionsController = [[[SubscriptionsController alloc] init] autorelease];
他のヒント
正しい。ビューが(最初のもの以外はまだロードされていない)ため、アイコンは表示されません。 ViewDidloadがそれまで呼び出されないため、ビューをタップするまでロードされません。
個々のuiviewcontrollers viewdidloadのコードを削除して、これを行います...
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;
所属していません StackOverflow