본문 바로가기

C/Objective C/ios

아이폰 Tab Bar Controller 만들기 예제 따라하기

- 아이폰의 Tab Bar 을 이용하여 여러개의 뷰를 한 화면에서 전환하면서 확인 할 수 있는 기능이다.


- 화면 디자인


- Tab Bar Controller 만들기 순서

1. Xcode 실행
2. Tabbed Application
3. Project Name : “TabbedTest” 

4. AppDelegate.h 파일 편집

5. AppDelegate.m 파일 편집

@interface AppDelegate : UIResponder <UIApplicationDelegate> { NSInteger myCount;

}
@property (nonatomic, assign) NSInteger myCount; @property (strong, nonatomic) UIWindow *window; @end

#import "AppDelegate.h"
@implementation AppDelegate
@synthesize myCount;
@synthesize window = _window;
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions

{ myCount = 0; return YES;

}

6. storyboard의 First View 위에 Label 위치
7. Assistant Editor로 Label 드래그 - “myLabel” 입력 

8. storyboard의 Second View 위에 Label 위치
9. Assistant Editor로 Label 드래그 - “myLabel” 입력 

10. FirstViewController.m 파일 편집

#import "FirstViewController.h" #import "AppDelegate.h" @implementation FirstViewController @synthesize myLabel

- (void)viewWillAppear:(BOOL)animated {

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.myCount++;
myLabel.text = [NSString stringWithFormat:@"<%d>", appDelegate.myCount];

[super viewWillAppear:animated]; }

11. SecondViewController.m 파일 편집

#import "SecondViewController.h" #import "AppDelegate.h" @implementation SecondViewController @synthesize myLabel

- (void)viewWillAppear:(BOOL)animated {

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.myCount++;
myLabel.text = [NSString stringWithFormat:@"<%d>", appDelegate.myCount];

[super viewWillAppear:animated]; }

12. storyboard에 View Controller 위치
13. View Controller 위에 Tab Bar Item 위치
14. Tab Bar Controller에서 Control 키를 누른 채 View Controller로 드래그 15. Relationship - View Controllers 선택
16. View Controller의 Tab Bar Item 선택 – Command+Option+4
17. Title - “Third”로 변경
18. Command+N – Objective-C class 선택
19. Class - “Third”, Subclass of - “UIViewController” 선택
20. storyboard에 View Controller 선택 – Command+Option+3
21. Class – ThirdViewController 선택
22. storyboard의 ThirdViewController에 Label 위치
23. Assistant Editor로 Label 드래그 - “myLabel” 입력
24. ThirdViewController.m 파일 편집

#import "ThirdViewController.h" #import "AppDelegate.h" @implementation ThirdViewController @synthesize myLabel

- (void)viewWillAppear:(BOOL)animated {

AppDelegate *appDelegate = [[UIApplication sharedApplication] delegate]; appDelegate.myCount++;
myLabel.text = [NSString stringWithFormat:@"<%d>", appDelegate.myCount];

[super viewWillAppear:animated]; }


- 실행 화면