존칭이 없는 포스트입니다. 양해 부탁드립니다 ^^

TabBar based로 프로젝트를 생성했을 경우 뷰에 있는 컨트롤을 동작시켜 본다.

TabBar based로 프로젝트를 생성한다.

1. FirstView에서 작업하기

먼저 FirstViewController 소스에 다음과 같이 추가한다.
이렇게 추가해 놔야 리소스 에디팅 (인터페이스 빌더)에서 아울렛을 연결할 수 있다.

FirstViewController.h

@interface FirstViewController : UIViewController {

IBOutlet UITextField *text1;

IBOutlet UIButton *button1;

}


- (IBAction) OnButtonDown: (id)sender;



@end


FirstViewControll.m

- (void)dealloc {

    [super dealloc];

}


- (IBAction) OnButtonDown: (id)sender

{

[text1 setText: @"Hello"];

}



@end


이제 저장을 한 후 MainWindow.xib를 더블클릭하여 인터페이스 빌더를 띄운다.

MainWindow.xib에 버튼과 텍스트필드를 추가한다.

문제는 MainWindow.xib안에 FirstViewController에 대한 ViewController가 없다. 
이 때 TabBar의 첫번째 First Item에서 오른클릭 해보자. 그러면 나온다;;
(이때 Tool/Inspector 창의  Class가 FirstViewController가 된 상태가 된다.)

아래처럼 button1, text1, OnButtonDown을 연결한다.


이렇게 하면 FirstView가 반응하게 된다.



2. SecondView 작업하기

SecondView는 이를 처리하는 ViewController가 프로젝트템플리트 소스에는 없다. 
따라서 먼저 SecondViewController 소스를 생성해야 한다. 

Project/ New Files 를 선택한 후
UIViewController로 선택한 후 SecondViewController이름으로 생성한다.

SecondViewController.h

@interface SecondViewController : UIViewController {

IBOutlet UITextField *stext1;

IBOutlet UIButton *sbutton1;

}


- (IBAction) OnSButtonDown: (id)sender;


@end


SecondViewController.m

- (void)dealloc {

    [super dealloc];

}


- (IBAction) OnSButtonDown: (id)sender

{

[stext1 setText: @"Hello Second"];

}




@end


저장한다.

이제 MainWindow.xib를 열어서 Second 탭바 아이템을 선택 한 후 아래처럼 Class를 SecondViewController로 변경한다.
Tools/Inspector를 연 후 네번째 탭의 Class을 아래 처럼 설정한다.



이제 SecondView.xib를 연다.
그리고 File's Owner의 inspector를 연 후 아래 처럼 class를 SecondViewController로 선택하고, 라이브러리 창으로 부터
텍스트 필드와 버튼을 올려 놓은다.



이제 File's Owner를 오른클릭하여 Second View의 sbutton1과 stext1, OnSButtonDown를 연결한다.



이제 실행 시켜 보면 두번째 뷰에서도 버튼이 동작함을 확인할 수 있다.

+ Recent posts