티스토리 뷰

원본링크:
XCode4: UITabBarController with UINavigationController using Interface Builder


1. 새 프로젝트 생성

Tab Bar Application 으로 시작합니다.

1. Create new project

2. 탭바 선택
MainWindow.xib 클릭하고 통합된 Interface Builder 왼쪽의 Objects 구역에서 Tab Bar Controller 선택.

2. Select Tab Bar

3. Navigation Controller 추가
화면 오른쪽 구석에서 Utilities box 클릭하고 Navigation Controller 찾아서 Tab Bar 중 중간 탭 안으로 드래그.
3. Expand Utility View and Add Navigation Controller

3b. Navigation Controller Added
중간 탭으로 추가한것을 보실 수 있습니다.
4. 새 탭 설정
Objects section으로 돌아가서 Navigation Controller 확장하고 View Controller 선택. 오른편 상단에서 Identity Inspector 선택하고 UIViewController의 클래스명을 입력. 이 데모에서는 "YourNewViewController"로 입력한다.

Attribute Inspector로 전환하고 NIB Name 부분에 XIB 파일명 입력.
주: .xib 확장자는 입력하지 말것, runtime crash를 유발함.

4b. Switch to Attribute Inspector and Fill in the nib name

5. 새 UI View Controller 생성
File 메뉴에서 파일 생성하고 UIViewController subclass 선택.

5. Create new UIViewController


5b. With XIB
With XIB for user interface 선택하도록 한다
5c. Use the same file name as before
이전에 쓴 파일명과 같게.

6. IBAction 추가
navigation controller에 뷰를 올리기 위해 버튼을 추가할것입니다. header 파일을 열고 action 추가.

8. Add an IBAction for our button
buttonPushView 줄만 추가됨

implementation 파일로 전환하고 pushViewController를 호출하는 몇줄을 추가.

9. Tell the navigationController to push a new View Controller
This is the simplest pushViewController line I could come up with

7. 버튼 추가
파일메뉴에서 YourNewViewController.xib 선택. 버튼 추가는 오른쪽 아래 Objects 구역에서 버튼 선택하여 뷰에 드래그/드롭.

다음은 버튼 오른쪽 클릭하고 Placeholders 구역의 File's Owner로 드래깅 후 buttonPushView 선택하여 버튼을 IBAction에 연결.

10. In the new XIB file drag in a button and link to the IBAction

8. 끝!
이제 빌드하고 실행 (Command-R).  두번째 탭을 선택하여 추가한 Navigation Controller를 확인하고 버튼 클릭후 행동을 봅시다.

8. Build and run the simulator. Press the button in the second bar item to try it out      8b. It works

댓글