InterfaceBuilderで作ったUITabBarItemをEnabled(選択可/選択不可)にする方法。
AppDelegate.h
IBOutlet UITabBarItem *IBTab1;
IBOutlet UITabBarItem *IBTab2;
IBOutlet UITabBarItem *IBTab3;
@property (nonatomic, retain) IBOutlet UITabBarItem *IBTab1;
@property (nonatomic, retain) IBOutlet UITabBarItem *IBTab2;
@property (nonatomic, retain) IBOutlet UITabBarItem *IBTab3;
AppDelegate.m
@synthesize IBTab1;
@synthesize IBTab2;
@synthesize IBTab3;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
IBTab1.enabled = NO; // 選択不可
IBTab2.enabled = YES; // 選択可
IBTab3.enabled = YES; // 選択可
}
InterfaceBuilderでは、それぞれのTabBarItemを、App DelegateのIBOutletの各項目と接続しておく。
利用用途としては、GPSやカメラなどデバイス特有の機能をTabBarItem割り付けておいて、iPod Touch上でアプリが動作しているときは選択させないようにする場合に用いる。
タグ:iPhone

