1. Project 생성
  1) Create a new Xcode Project -> Window based Application -> "TabBarNavi"

2. Tabbar 구현
  1) Interface Builder 실행(Mainwindow.xib 더블클릭) -> Library 창실행 (shift + Cmmnd + L ) ->Tab Bar Controller를 MainWindow.xib 윈도우로 Drag & Drop
  2) Tab Bar Controller 연동하기
    a. header 파일에 IBOutlet UITabBarController *mainTab; 선언
    b. source 파일에서 [window addSubview:mainTab.view]; 와 해제시 [mainTab release];를 선언함.
    c. MainWindow.xib 화면에서 App Delegate와 Tab Bar Controller의 mainTab을 연결함
  3) Tab Bar Controller 설정 
    a. MainWindow.xib 화면에서 Tab Bar Controller 선택 후 Attributes 창 실행 (Cmmnd +1)
    b. View Controllers 항목의 Title을 변경하고(첫번째, 두번째), Class 항목을 View Controller를 Navigation Controller로 변경함.
    c. "+" 버튼을 눌러, "세번째" Navigation Controller를 추가함. 
    d. 배경이 투명한 이미지를 활용하여 Tab 이미지 추가
      - resource 폴더에서 세개의 이미지 추가
      - MainWindow.xib 화면에서 Tab Bar Controller Tree 구조를 확장시킨 후, 각 Tab Bar Item의 Atrributes 윈도우에서 "Image"항목에서 해당하는 이미지를 지정함 

4. 뷰구현
  1) 세개의 뷰를 추가 
     a. Class 폴더 마우스 우측 클릭, Add -> New File -> "UIView Controller subClass" with Xib for user interface
         "FirstViewList", "SecondView", "ThirdView" 추가
  2) FirstViewList 에 Table View 연결
     a. FirstViewList.Xib를 열고, 라이브러이에서 "Table View"를 Drag  Drop한다.
     b. Table View 를 선택하고, FirstViewList의 File's Owner에 드래그해서, datasource와 delegate를 연결한다. 
     c. FirstViewList의 source파일에 table view의 필수함수 구현 (FirstViewList.m)
...

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *kIdentifier = @"cell";
 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:kIdentifier];
 
if(cell == nil)
{
  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:kIdentifier] autorelease];
}
 
cell.textLabel.text = @"첫번째 뷰 리스트 입니다.";
 
return cell;
 }

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
 return 5;
}

...


continue ....





  3) View Controller Xib 연결하기
    a. Tab Bar Controller를 펼쳐 각 탭에 해당하는 View Controller를 선택하여 Attribute창(Cmmnd+1)에서 각각 해당하는 Xib를 설정하고, Identity창(Cmmnd+4)에서 Class를 신규로 추가한 클래스를 각각 지정한다. 

  4) Xib title 변경하기
-(id) initWithCoder:(NSCoder *)aDecoder
{
if(self =[ super initWithCoder:aDecoder])
{
self.title = @"첫번째 ^^";
}
 
return self;
}
 
5. Navigation 구현하기
  1) Detail 뷰추가 
    a. Class 폴더 마우스 우측 클릭, Add -> New File -> "UIView Controller subClass" with Xib for user interface
         "FirstViewDetail" 추가
    b. Label 객체 " 디테일 뷰 입니다." 추가
  2) 첫번째 테이블 화면에서, 각 셀 클릭시 디테일 뷰로 전환
...

#import "FirstViewDetail.h"

...

(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *naviCtrl = self.navigationController;
 
FirstViewDetail  *FViewDetail= [[FirstViewDetail alloc]initWithNibName:@"FirstViewDetail"  bundle:nil];
 
[naviCtrl pushViewController:FViewDetail animated:YES]; 
}

  3) 두번째, 세번째 뷰에서 라벨 추가
   
Posted by 꿈을펼쳐라
,