1. 프로젝트 생성
1) Xcode - Create a new Xcode Project - Window Based Project - "MultiXib"
2) "Navigation Controller" 추가
3) Navigation Controller 관련 소스 추가
@interface MultiXibAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;IBOutlet UINavigationController *naviCtrl;}
2. Xilb 파일 생성- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch
[window addSubview:naviCtrl.view];
[window makeKeyAndVisible];
return YES;
}
- (void)dealloc {[naviCtrl release];[window release];[super dealloc];}
1) class 항목에서 마우스 우클릭 -> Add -> New File ... ( 혹은 메뉴에서 File -> New File ...) 실행
2) iPhone OS 항목중 Cocoa Touch Class를 선택하고, UIViewController 선택.
3) option항목중 "With XIB for user interface"를 선택. Next
4) 클래스 이름을 입력함 ( mainView, firstView, secondView 추가)
3. mainView MainWindow에 나타내기
1) mainView.xib를 선택, view에 구분가능한 라벨 추가
2) MainWindow.xib에서 "Navigation Controller"를 선택하고 Atrribute(Cmmnd + 1)창을 띄움
3) NIB 입력항목에 구현하고자 하는 .xib를 하나 선택함 (Main View
4. TaleView 및 Navigation 기능 구현
1) mainView에 TableView를 드럽하고, File owner's와 DataSource, Dellegate를 연결
2) mainView.m 파일에 Table View의 필수 함수를 구현
3) 셀을 클릭했을 때, 각가의 xib와 연결하여는 기능
#import "MainXib.h"
#import "FirstXib.h"
#import "SecondXib.h"
@implementation MainXib
/*
// The designated initializer. Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
// Custom initialization
}
return self;
}
*/
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
[super viewDidLoad];
}
*/
/*
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
- (void)viewDidUnload {
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(int)section
{
return 2;
}
- (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];
}
if(indexPath.row==0)
{
cell.textLabel.text = @"첫번째 항목입니다.";
}
else
{
cell.textLabel.text = @"두번째 항목입니다.";
}
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UINavigationController *mainNavCon = self.navigationController;
if(indexPath.row==0)
{
FirstXib *firstView = [[FirstXib alloc]initWithNibName:@"FirstXib" bundle:nil];
[mainNavCon pushViewController:firstView animated:YES];
}
else
{
SecondXib *secondView = [[SecondXib alloc]initWithNibName:@"SecondXib" bundle:nil];
[mainNavCon pushViewController:secondView animated:YES];
}
}
- (void)dealloc {
[super dealloc];
}
'아이폰개발 > AppsNext강좌정리' 카테고리의 다른 글
[AppsNext] iPhone SDK 기본강좌_8강 Xib 파일간 값 전달 (0) | 2010.06.18 |
---|---|
[AppsNext] iPhone SDK 기본강좌_7강 탭바컨트롤러(테이블+네비게이션+탭바) (0) | 2010.06.17 |
[AppsNext] iPhone SDK 기본강좌_5강 Navigation Controller (0) | 2010.06.13 |
[AppsNext] iPhone SDK 기초강좌_4강 View 전환해 보기 (0) | 2010.06.13 |
[AppsNext] iPhone SDK 기초강좌_3강 Table Control (4) | 2010.06.12 |