본문 바로가기
iPhone 개발

TabBar 사용하기-1

by GoodDev 2012. 10. 11.

탭바를 사용하기 위해서 수행하는 순서는 다음과 같다.

1. 먼저 UITabBarController 객체를 생성한다.

2. 각 탭에 연결할 ViewController 들을 생성한다.

3. 2번에서 만든 Viewcontroller들을 배열에 추가한다.

4. UITabBarController의 viewControllers 속성에 3번에서 만든 배열을 할당한다.

5. window의 rootViewController를 1번에서 생성한 탭바 객체로 설정한다.


실제 코드를 참고하자.

AppDelegate.h

#import <UIKit/UIKit.h>


@interface AppDelegate : UIResponder <UIApplicationDelegate>

{

    UITabBarController *tabbarctl;

}


@property (strong, nonatomic) UIWindow *window;

@property (nonatomic,retain)UITabBarController *tabbarctl;

@end



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{

    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];

    // Override point for customization after application launch.

    self.window.backgroundColor = [UIColor whiteColor];

    /* Tabbar Controller */

   // 1번에 해당

    tabbarctl = [[UITabBarController alloc] init];

    

    /* Default View - 2번에 해당 */

    ViewController *vc1 = [[ViewController alloc] init];

    ViewController *vc2 = [[ViewController alloc] init];

    

   //3,4번에 해당

    NSArray *ctls = [NSArray arrayWithObjects:vc1,vc2, nil];

    tabbarctl.viewControllers = ctls;

    

   // 5번에 해당

    self.window.rootViewController = tabbarctl;

    [self.window makeKeyAndVisible];

    return YES;

}



댓글