1. 프로젝트 생성하기
1) Create a Xcode Project :View-based Project - "TableViewControl"
=> 이름이 너무 길어, 나중 아이폰 실행화면에서, 아이폰 밑의 실행화일 명칭이 축소 생략되어 나타남.
( 프로젝트 생성시 향후 실행화일 명을 고려해서, 적당한 길이로 명명)
2) TableViewControlViewController.xib 더블클릭 Interface Builder 실행
1) Create a Xcode Project :View-based Project - "TableViewControl"
=> 이름이 너무 길어, 나중 아이폰 실행화면에서, 아이폰 밑의 실행화일 명칭이 축소 생략되어 나타남.
( 프로젝트 생성시 향후 실행화일 명을 고려해서, 적당한 길이로 명명)
2) TableViewControlViewController.xib 더블클릭 Interface Builder 실행
3) Library[Cmmnd + Shift + L ] 실행
a. Object - Library - Cocoa Touch - Data Views - Table View 선택( Table View Controller 가 아님.)
b. "Table View"를 TableViewViewControler.xib의 View 화면 위로 Drag& Drop : 위치 약간 조절
4) Inspector [Cmmnd + Shift + I] 실행 ( Table View 가 선택된 상태에서 실행)
a. Identity tab :
- Style : plain / group
- Separator : None, Single Line, Single Line Etched (엷게 드러내다 : pain 뷰에서는 지원되지 않음)
# 해당위치에 마무스를 고정시켜 놓으면 각 항목에 해당하는 풍선도움말이 나타남.
5) 아웃렛 연결하기
a. View에 있는 "Table View"를 선택 (화면 반전, 잘 안 될경우, Title Bar "View" 부분 클릭후 재시도)
b. 선택한 상태에서 "Ctrl"을 누른 상태에서, File's Owner에 -datasource, -delegate에 연결
(마우스 오른쪽 클릭 후 Drag해도 동일 효과)
- datasource / delegate 두개는 protocol로 IB를 사용하지 않는다면 하나하나 코딩을 추가해야 한다.
- datasource : table에 표현되는 data의 속성 설정
- delegate : table 자체 속성을 설정
6) 필수 함수 구현하기
a. source 파일을 선택 (*.h, *.m)
b. 메뉴 : Help - Developer Documentation
c. UITableViewDataSource 입력 :
Tasks - Configuring a Table View 항목에서 "required method"라는 항목을 확인 할 수 있음.
d. 위 "c"항목의 두개 함수 원형을 도움말에서 복사해서, "TableViewControlViewController.m" 파일에
함수 형태로 추가
2. 각 셀 항목에 특정 Data의 내용이 나타나도록 구현
1) NSArray에 임의의 Text를 넣고, 각셀에 해당 내용이 출력되는 기능 구현
2) 클래스 멤버 변수로 활용하기
a. "TableViewControlViewController.h " 파일에 TableViewControlViewController클래스 내부에 선언
a. Object - Library - Cocoa Touch - Data Views - Table View 선택( Table View Controller 가 아님.)
b. "Table View"를 TableViewViewControler.xib의 View 화면 위로 Drag& Drop : 위치 약간 조절
4) Inspector [Cmmnd + Shift + I] 실행 ( Table View 가 선택된 상태에서 실행)
a. Identity tab :
- Style : plain / group
- Separator : None, Single Line, Single Line Etched (엷게 드러내다 : pain 뷰에서는 지원되지 않음)
# 해당위치에 마무스를 고정시켜 놓으면 각 항목에 해당하는 풍선도움말이 나타남.
5) 아웃렛 연결하기
a. View에 있는 "Table View"를 선택 (화면 반전, 잘 안 될경우, Title Bar "View" 부분 클릭후 재시도)
b. 선택한 상태에서 "Ctrl"을 누른 상태에서, File's Owner에 -datasource, -delegate에 연결
(마우스 오른쪽 클릭 후 Drag해도 동일 효과)
- datasource / delegate 두개는 protocol로 IB를 사용하지 않는다면 하나하나 코딩을 추가해야 한다.
- datasource : table에 표현되는 data의 속성 설정
- delegate : table 자체 속성을 설정
6) 필수 함수 구현하기
a. source 파일을 선택 (*.h, *.m)
b. 메뉴 : Help - Developer Documentation
c. UITableViewDataSource 입력 :
Tasks - Configuring a Table View 항목에서 "required method"라는 항목을 확인 할 수 있음.
d. 위 "c"항목의 두개 함수 원형을 도움말에서 복사해서, "TableViewControlViewController.m" 파일에
함수 형태로 추가
// Table Cell 갯수
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 5;}
// indexPath에 해당하는 셀 생성
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cIdentifier];
if(cell ==nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cIdentifier]autorelease];
}
cell.textLabel.text = @"아이폰 개발은 정말 재미있어~ ";
return cell;
}
2. 각 셀 항목에 특정 Data의 내용이 나타나도록 구현
1) NSArray에 임의의 Text를 넣고, 각셀에 해당 내용이 출력되는 기능 구현
2) 클래스 멤버 변수로 활용하기
a. "TableViewControlViewController.h " 파일에 TableViewControlViewController클래스 내부에 선언
b. "TableViewControlViewController.m" 파일에 다음의 내용 추가@interface TableControlViewController : UIViewController {
NSArray *listData;
}
//Object-C에서 해당값을 사용하기 위한 get, set 관련 내용은 메크로 처리인듯함.( 확인필요)
@property (nonatomic, retain) NSArray *listData;
3) 해당변수배열(listData)에 초기값 넣기#import "TableControlViewController.h"
@implementation TableControlViewController
// 뭐 헤더에서 선언한 listData를 동기화 해서 사용하겠단 그런 이야기 겠지.
@synthesize listData;
4) 추가한 함수에 해당 내용 반영하기 및 메모리 삭제하기// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad {
// NSArray 입력값의 맨 마지막이 "nil"임을 확인하자!listData = [NSArray arrayWithObjects:@"SimVerse = Sim(ulate) + (Uni)Verse", @"세상을 시뮬레이션 하자", @"너무 허황되다구? ",@"난 가능하다고 생각해", @"힌트는 SNS 야", @"미래는 꿈 꾸는 자의 것이 아니라, 실천하는 자의 것이다.",nil];
[super viewDidLoad];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [listData count] ;
}- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *cIdentifier = @"cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cIdentifier];
if(cell ==nil)
{
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cIdentifier]autorelease];
}
cell.textLabel.text = [listData objectAtIndex:indexPath.row];
return cell;
}
- (void)dealloc {
[listData release];
[super dealloc];
}
[질문] 어떤때는 return [listData count]와 같이 [ ]의 용도는? (음.. 역시 Object-C도 빨랑 시작해야 겠군)
'아이폰개발 > AppsNext강좌정리' 카테고리의 다른 글
[AppsNext] iPhone SDK 기본강좌_6강 다중 Xib 사용하기 (0) | 2010.06.15 |
---|---|
[AppsNext] iPhone SDK 기본강좌_5강 Navigation Controller (0) | 2010.06.13 |
[AppsNext] iPhone SDK 기초강좌_4강 View 전환해 보기 (0) | 2010.06.13 |
[AppsNext] iPhone SDK 기초강좌_2강 HelloWorld, 그리고 XCode 설명 (0) | 2010.06.11 |
[AppsNext] iPhone SDK 기초강좌_1강 들어가면서 (0) | 2010.06.10 |