테이블 뷰에서 여러 항목을 선택해야하며 선택한 항목 (예 : 배열이나 다른 항목에 저장하는 것과 같은 항목)을 추적해야합니다. 지금까지의 나의 접근 방식; 테이블에서 여러 레코드 선택
- (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];
}
cell.textLabel.text=[arrayobject objectAtIndex:indexPath.row];
bool xx = [[allmyselectedobjects objectAtIndex:indexPath.row] containsIndex:1];
if (xx) {
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
}else{
[cell setAccessoryType:UITableViewCellAccessoryNone];
}
return cell;
}
과 didSelectRowAtIndexPath 방법
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [self.cuisineTableView cellForRowAtIndexPath:indexPath];
if ([cell accessoryType] == UITableViewCellAccessoryNone) {
[cell setAccessoryType:UITableViewCellAccessoryCheckmark];
[self.allmyselectedobjects insertObject:1 atIndex:indexPath.row];
}
else {
[cell setAccessoryType:UITableViewCellAccessoryNone];
[self.allmyselectedobjects insertObject:0 atIndex:indexPath.row];
}
}
내가 여러 레코드를 클릭 수,하지만 난 아래로 스크롤 할 때 나는 또한 (내가 선택하지 않은) 체크 표시가 쳤다 다른 세포를 참조하십시오. 지금이 코드를 수정 해 보았습니다. 누군가이 코드를 수정하도록 도와 줄 수 있습니까?
자, 그럼 그걸 프로그램 적으로 해결할 수 있을까요? – Illep
위의 그림과 같이 NSIndexSet을 사용하여 선택된 셀 행 인덱스를 저장합니다. –
의미 NSIndexSet에 의해, 당신은 NSMutableArray가 아닌 NSIndexSet으로 allmyselectedobjects의 유형을 변경 했습니까? – Illep