vincenthanna - Passion, Grace and Fire.

vh1981.egloos.com

포토로그 마이가든



아이폰 개발 - UITabBarController 사용(interface builder없이 구현하기) iphone개발

application delegate에서 앱의 window의 가장 첫번째 subView로 tabBar의 view를 넣고, tabBarController에 viewController들을 추가하면 된다.


대부분 view 이동에 navigationController를 사용하므로 viewController로 초기화된 navigationController를 넣어도 된다.


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

{

    // 가장 최상위에 깔아놓는 Window 생성한다.

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

    

    // tabBar 생성한다.

    _tabBarController = [[UITabBarController alloc] init]; 

    _tabBarController.customizableViewControllers = nil;

    

    // root 사용될 ViewController 생성한다.

    viewController = [[test1ViewController alloc]init];

    _navigationController = [[UINavigationController alloc]initWithRootViewController:viewController];

    

    _viewController2 = [[test2ViewController alloc]init];

    _navigationController2 = [[UINavigationController alloc] initWithRootViewController:_viewController2];

    

    // tabBar 위에서 생성한 navigationController들을 넣는다.

    _tabBarController.viewControllers = [NSArray arrayWithObjects: _navigationController, _navigationController2, nil]; 

    

    // tabBar window 가장 처음 view 넣는다.

    // Override point for customization after application launch.

    //[self.window addSubview:_navigationController.view];

    [self.window addSubview:_tabBarController.view];


    

    self.window.backgroundColor = [UIColor whiteColor];

    [self.window makeKeyAndVisible];

    return YES;

}


1 2 3 4 5 6 7 8 9 10 다음