UITableView - 7. 테이블 셀 이동하기

Published on: 2011. 11. 18. 01:21 by louis.dev

데이블 데이터 삭제하기에 이어 계속 진행 해보도록 하겠다. 테이블 셀을 이동시키는 것은 다음과 같은 delegate method만 구현 하면 된다.

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath;
- (void) tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath; 

첫번째 메소드는 이동시킬수 있는 셀인지 아닌지 알아보는 메소드로서 간단하게 YES만 리턴해 주면 된다.
두번째 메소드는 실제 셀이 이동할때 실행되는 메소드이다. 그러므로 여기에서 실제 데이터의 이동을 구현해 주면 된다.


 

UITableView - 6. 테이블 데이터 삭제 하기

Published on: 2011. 11. 17. 18:47 by louis.dev

1. 프로젝트 생성 후 다음과 같이 toolbar와 toolbar button 그리고 그 하단에 TableView를 넣습니다. 레이아웃을 작성합니다.
 

2. TableView의 dataSource와 delegate를 File's owner와 연결 시킵니다.
 

3. ViewController.h와 ViewController.m을 다음과 같이 작성한다.


 

UITableView - 5. Cell tap시 수행되는 delegate method

Published on: 2011. 11. 17. 18:14 by louis.dev
 -(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIntexPath *)indexPath {
     indexPath.section     //선택된 섹션
     indexPath.row         //선택된 row


UITableView - 4. TableViewCell의 타입과 Accessory

Published on: 2011. 11. 17. 18:07 by louis.dev

1. Cell을 생성할때 Type을 지정해 주고, Accessory타입을 지정하면 쉽게 타입과 악세서리를 설정할 수 있다.

[실행결과]

그리고 다른 Accessory타입과는 다르게 실행화면의 맨마지막에 있는 UITableViewCellAccessoryDetailDisclosureButton(파란원모양의 악세서리)는 delegate를 통해서 터치를 처리 할 수 있다(셀 전체를 터치하는 것이 아니라 파란원 아이콘을 탭했을 때만 실행되는 델리게이트).

해당 터치를 사용하려면 다음의 델리게이트 메소드를 작성하면 된다.
- (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath


 

UITableView - 3. 테이블뷰 그룹으로 만들기

Published on: 2011. 11. 17. 16:55 by louis.dev
테이블뷰를 그룹으로 만드는 것은 Interface Builder의 속성변경으로 간단하게 처리가 가능합니다.
이전에 작업했던 소스에서 ViewController.xib를 여신 후 TableView의 "style" 속성을 "grouped"로 변경해 주시면 됩니다.
 

[실행화면]