먼저이 방법을 편집해야합니다 (- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
). 탐색 기반 응용 프로그램을 생성했다고 가정하면이 메서드는 이미 주석 처리되어 있어야합니다. 귀하의 구현의 정확한 세부 사항을 모르겠지만 어떻게 든 tableView의 각 셀에 대한 체크 박스 상태를 추적해야합니다. 당신이 BOOL 배열을 가지고 예를 들어, 다음 코드는 작동합니다 :
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
if (checkboxArray[indexPath.row])
checkboxArray[indexPath.row] = NO;
else
checkboxArray[indexPath.row] = YES;
[self.tableView reloadData];
}
을 이제 우리는, 다음 단계는 셀이 표시되는 방법을 수정하는 것입니다 그들 옆에 체크 표시를 할 필요 세포 알고 . - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
은 각 셀의 도면을 처리합니다. 우리가 reloadData를 호출하지 않는 경우는 오프 스크린 가서 다시 나타날 때까지
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
}
if (checkboxArray[indexPath.row]) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
}
else
cell.accessoryType = UITableViewCellAccessoryNone;
// Configure the cell.
return cell;
}
이 확인 표시가 표시되지 않습니다 : 앞의 예를 구축, 이것은 당신이 체크 박스를 표시 할 방법이다. 셀을 재사용하는 방법 때문에 매번 accessoryType을 명시 적으로 설정해야합니다. 셀을 선택했을 때만 스타일을 설정하면 스크롤 할 때 체크되지 않을 수도있는 다른 셀에 체크 표시가 생깁니다. 바라기를이 체크 표시를 사용하는 방법에 대한 일반적인 아이디어를 제공합니다.