1. Project 생성하기
1) Create a new Xcode Project -> Window-Base Application -> "NaviTest"
2. Navigation Control 구현하기
1) IB 실행시킨 상태에서 Library창에서 Navigation Controller를 MainWindow.xib 창으로 Drag&Drop
2) 헤더 파일에 해당변수 선언 / View 적용, 소스파일에서 해제
3) MainWindow.xib에서 "Navi Test App Delegate"를 Drag&Drop으로 Navigation Controller에 한후, 헤더에서 선언한 mainNav를 선택함 ( Drag & Drop 방향 중요 : 반대방향으로 하면 다른 팝업이 뜸)@interface NaviTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UINavigationController *mainNav;
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {(## 향후 소스코드 내용은 포함은 헤더파일은 연두색, 소스파일은 하늘색으로 표현할 예정임)
// Override point for customization after application launch
[window addSubview:mainNav.view];
[window makeKeyAndVisible];return YES;
}
- (void)dealloc {
//IBOutlet으로 선언한 변수는 반드시 해제해야함[mainNav release];
[window release];
[super dealloc];
}
3. View 추가하기
1) Library 창에서 "View Controller"를 선택해서 MainWindow.xib로 Drag & Drop하여 3개를 만들고, 각 View Controller의 Title을 "root/first/second:ViewController"로 설정한다. (Attributes 창에서 : Cmmnd + 1)
2) View Controller에서 다른 Control이나 Object를 바로 올리면 안되고, Cocoa Touch에서 "View"를 Drag & Drop해서 화면을 덮어줘야 가능함.
3) 각 뷰에 적당한 Label을 입력
4) Source 추가
5) Delegate 연결 : MainWindow.xib의 "Navi Test App Delegate"를 각 View Controller에 Drag & Drop한 후 해당하는 변수에 연결한다.@interface NaviTestAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
IBOutlet UINavigationController *mainNav;
IBOutlet UIViewController *rootView;
IBOutlet UIViewController *firstView;
IBOutlet UIViewController *secondView;
// 위를 이렇게 선언해도 문제는 없음 <---
// IBOutlet UIViewController *rootView, *firstView, *secondView;
// --->
}
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {(## 향후 소스코드 내용은 포함은 헤더파일은 연두색, 소스파일은 하늘색으로 표현할 예정임)
mainNav.viewControllers =[NSArray arrayWithObject:rootView];
rootView.title =@"나는 루트뷰입니다.";// Override point for customization after application launch
[window addSubview:mainNav.view];
[window makeKeyAndVisible];return YES;
}
- (void)dealloc {
//IBOutlet으로 선언한 변수는 반드시 해제해야함
[rootView release];
[firstView release];
[secondView release];
[mainNav release];
[window release];
[super dealloc];
}
4. 화면전환 네비게이션 구현하기
1) rootView의 Label을 지우고, "table view"를 rootView window에 올려놓는다.
2) "table view"를 사용할 때는 기계적으로 App Delegate와 dataSource/Delegate를 연동한다.
3) table view의 require function을 추가
- (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];
}
if (indexPath.row ==0) {
cell.textLabel.text = @"첫번째 행입니다.";
}
else {
cell.textLabel.text =@"두번째 행입니다.";
}
return cell;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
4) firstView, SecondView 도 rootView와 마찬가지로 윈도우 위에 View를 덮고, 식별할 수 있는 라벨을 추가한다.
5) UITableViewDelegate의 도움말을 확인하여 필요한 함수 검색 ( 셀 마우스 클릭시 동작 이벤트 처리)
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(indexPath.row ==0)
{
[mainNav pushViewController:firstView animated:YES];
}
else
{
[mainNav pushViewController:secondView animated:YES];
}
}
'아이폰개발 > AppsNext강좌정리' 카테고리의 다른 글
[AppsNext] iPhone SDK 기본강좌_7강 탭바컨트롤러(테이블+네비게이션+탭바) (0) | 2010.06.17 |
---|---|
[AppsNext] iPhone SDK 기본강좌_6강 다중 Xib 사용하기 (0) | 2010.06.15 |
[AppsNext] iPhone SDK 기초강좌_4강 View 전환해 보기 (0) | 2010.06.13 |
[AppsNext] iPhone SDK 기초강좌_3강 Table Control (4) | 2010.06.12 |
[AppsNext] iPhone SDK 기초강좌_2강 HelloWorld, 그리고 XCode 설명 (0) | 2010.06.11 |