※ 주 업이 iPhone 개발이 아니라서 가끔 잊어먹게 되는 팁입니다.
1. New Project에서 Window-based Application 선택
2. 기본 AppDelegate명을 변경
생성후에 XxxAppDelegate와 같이 프로젝트명이 앞에 붙는데 이를 제거하여 네이밍을 단순화하기 위해 파일명과 클래스명을 모두 변경한후, MainWindow.xib에서도 클래스명을 변경해준다.
3. Tab Bar Controller 추가
Library에서 Tab Bar Controller를 MainWindow.xib에 넣는다.
4. Tab Bar Controller를 위해 AppDelegate.h 소스 수정
@interface AppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UITabBarController *tabBarCtrl;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarCtrl;
UIWindow *window;
IBOutlet UITabBarController *tabBarCtrl;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet UITabBarController *tabBarCtrl;
5. Tab Bar Controller를 위해 AppDelegate.m 소스 수정
@implementation AppDelegate
@synthesize window;
@synthesize tabBarCtrl;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSMutableArray *tabs = [[[NSMutableArray alloc] init] autorelease];
tabBarCtrl.viewControllers = tabs;
tabBarCtrl.customizableViewControllers = tabs;
[window addSubview:tabBarCtrl.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[tabBarCtrl release];
[window release];
[super dealloc];
}
@synthesize window;
@synthesize tabBarCtrl;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
NSMutableArray *tabs = [[[NSMutableArray alloc] init] autorelease];
tabBarCtrl.viewControllers = tabs;
tabBarCtrl.customizableViewControllers = tabs;
[window addSubview:tabBarCtrl.view];
[window makeKeyAndVisible];
}
- (void)dealloc {
[tabBarCtrl release];
[window release];
[super dealloc];
}
6. Tab Bar Controller와 AppDelegate를 연결시킨다.
7. Tab 추가 방법
AppDelegate.h
IBOutlet UINavigationController *funcCatNavigationController;
@property (nonatomic, retain) IBOutlet UINavigationController *funcCatNavigationController;
AppDelegate.m
funcCatNavigationController.tabBarItem.image = [UIImage imageNamed:@"tb_icon_func.png"];
funcCatNavigationController.tabBarItem.title = @"함수";
[tabs addObject:funcCatNavigationController];
IBOutlet UINavigationController *funcCatNavigationController;
@property (nonatomic, retain) IBOutlet UINavigationController *funcCatNavigationController;
AppDelegate.m
funcCatNavigationController.tabBarItem.image = [UIImage imageNamed:@"tb_icon_func.png"];
funcCatNavigationController.tabBarItem.title = @"함수";
[tabs addObject:funcCatNavigationController];
