티스토리 뷰

iOS/자료정리

[iPhone]TableView 사용

감성개발자 썩소천사 2011. 3. 14. 17:04
반응형

TableView 기본 구성

.h

<UITableViewDelegate, UITableViewDataSource> 

UITableView *alarmList;



.m

//생성.

alarmList = [[UITableView alloc] initWithFrame:CGRectMake(0, 45, 320, 366) style:UITableViewStylePlain];

alarmList.delegate = self;

alarmList.dataSource = self;

[self.view addSubview:alarmList];

[alarmList release];



//필수 함수

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section

{

return 2;

}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath

{

//AlarmListCell *cell = (AlarmListCell *)[tableView dequeueReusableCellWithIdentifier:@"acell"];

UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"acell"];

if (cell == nil)

{

///cell = [[[AlarmListCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"acell"] autorelease];

cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:@"acell"] autorelease];

}

cell.textLabel.text = @"오전9:33";

cell.detailTextLabel.text = @"알람";

[cell.textLabel setFont:[UIFont systemFontOfSize:17]];

cell.accessoryView = [[[UISwitch alloc] initWithFrame:CGRectZero] autorelease];

cell.editingAccessoryType = UITableViewCellAccessoryDisclosureIndicator;

return cell;

}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

}

//accessory선택시 호출함수
-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 

//cell의 선 스타일 조절

alarmList.separatorStyle 
0 -> 숨김  2->내용이 있는 셀만 숨김

//cell 선 색상 조절
alarmList.separatorColor = [UIColor whiteColor];

//cell 기본높이및 전체 높이 고정
alarmList.rowHeight = 80.0;

//edit모드에서 셀 선택하기

alarmList.allowsSelectionDuringEditing = YES

//전체 테이블 선택 방지

alarmList.allowsSelection = NO;

//특정 cell선택 방지

cell.selectionStyle = 0;

//cell선택 남아있는거 해결하고 싶을때는

UITableViewCell *cell = [alarmList cellForRowAtIndexPath:indexPath];

cell.selected = NO;

//cell Edit 모드에서 애니메이션
[tableName deleteSections:[NSIndexSet indexSetWithIndex:indexPath.section] withRowAnimation:UITableViewRowAnimationLeft];
또는
[tavleName deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];



//테이블 위치 재정렬 하기. indPath에 이동할 위치를 넣어주면 됨.
NSIndexPath *indPath = [NSIndexPath indexPathForRow:0 inSection:0];
[recordListView scrollToRowAtIndexPath:indPath atScrollPosition:UITableViewScrollPositionTop animated:YES];

 


반응형

'iOS > 자료정리' 카테고리의 다른 글

[iPhone]화면 회전  (0) 2011.04.13
[iPhone]TabbarController  (0) 2011.04.12
[iPhone][UIApplication sharedApplication]  (0) 2011.04.07
[iPhone]NSDate  (0) 2011.03.18
[iPhone]TableView 사용  (0) 2011.03.14
[iphone]sqlite에 엑셀(xls) 파일 집어 넣기.  (0) 2011.02.07
댓글
댓글쓰기 폼
공지사항