したがって、UIViewController
にはUITabBar
というビューがあります。 JSONをプルダウンして、どのタブをタブバーに追加するかを決めたので、実行時にタブを選択できるようにする必要があります。私はUITabBarController setViewControllers:animated:
メソッドを使用して、ビューコントローラのリストを追加したかったのです。しかし、私はビューコントローラでこれをやっているので、タブバーのView Controllerにアクセスする方法はわかりません。ここに私のコードがある...UIViewControllerのUITabBarにUITabBarItemを追加する
ヘッダー
#import <UIKit/UIKit.h>
@interface HealthTicketTabController : UIViewController <UITabBarDelegate, UITabBarControllerDelegate> {
NSArray *viewControllers;
IBOutlet UITabBar *tabBar;
UIViewController *selectedViewController;
// How do I link this the the tabBar's view controller???
UITabBarController *tabBarController;
}
@property (nonatomic, retain) NSArray *viewControllers;
@property (nonatomic, retain) IBOutlet UITabBar *tabBar;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarController;
@property (nonatomic, retain) UIViewController *selectedViewController;
@end
ソース
- (id)init
{
self = [super initWithNibName:@"HealthTicketTabView" bundle:nil];
if (self)
{
//Controllers for the tab view
HealthCardController *card = [[HealthCardController alloc] init];
MedicalExpensesController *medical = [[MedicalExpensesController alloc] init];
//Tab bar items to be displayed in the tab bar
card.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:0];
medical.tabBarItem = [[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemMostViewed tag:1];
NSArray *array = [[NSArray alloc] initWithObjects:card, medical, nil];
//Set the tab bar's view controllers to the list
tabBarController.viewControllers = [NSArray arrayWithObjects:card, medical, nil];
[array release];
[card release];
[medical release];
}
return self;
}