한 섹션에서 한 번에 하나의 UITableViewCell 만 검사하도록 허용하고 있습니다. 내가 할 일은 체크 된 UITableViewCell (있는 경우)의 선택을 취소하고 현재 선택한 셀을 확인하는 것입니다. 그래서 기본적으로 하나의 CellA가 선택되고 CellB를 선택하면 CellA에서 선택을 취소하고 CellB에서 선택합니다. 여기 하나의 UITableViewCell 섹션에서 체크 허용을 허용
내가 시도하고 달성하기 위해 무슨 짓을했는지의이 :- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(![self.selectedIndexPaths containsObject:indexPath]) {
[self.selectedIndexPaths addObject:indexPath];
}
else {
[self.selectedIndexPaths removeObject:indexPath];
}
if (indexPath.section == 0) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else if (indexPath.section == 1) {
if (![self.selectedIndexPaths containsObject:indexPath]) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else {
for (NSIndexPath *indexPath2 in self.selectedIndexPaths) {
if (indexPath2.section == 1) {
[tableView cellForRowAtIndexPath:indexPath2].accessoryView.hidden = YES;
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
}
}
}
else if (indexPath.section == 2) {
if (![self.selectedIndexPaths containsObject:indexPath]) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else {
for (NSIndexPath *indexPath2 in self.selectedIndexPaths) {
if (indexPath2.section == 2) {
[tableView cellForRowAtIndexPath:indexPath2].accessoryView.hidden = YES;
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
}
}
}
}
-(void)tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.section == 0) {
if ([tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden == YES) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = YES;
}
}
else if (indexPath.section == 1) {
if (![self.selectedIndexPaths containsObject:indexPath] && [tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden == YES) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else if (![self.selectedIndexPaths containsObject:indexPath] && [tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden == NO){
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = YES;
}
else {
for (NSIndexPath *indexPath2 in self.selectedIndexPaths) {
if (indexPath2.section == 1 && [tableView cellForRowAtIndexPath:indexPath2].accessoryView.hidden == YES) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
}
}
}
else if (indexPath.section == 2) {
if (![self.selectedIndexPaths containsObject:indexPath] && [tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden == YES) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
else if (![self.selectedIndexPaths containsObject:indexPath] && [tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden == NO){
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = YES;
}
else {
for (NSIndexPath *indexPath2 in self.selectedIndexPaths) {
if (indexPath2.section == 2 && [tableView cellForRowAtIndexPath:indexPath2].accessoryView.hidden == YES) {
[tableView cellForRowAtIndexPath:indexPath].accessoryView.hidden = NO;
}
}
}
}
}
당신이 볼 수 있듯이, 내가 세 개의 섹션이 있고, 첫 번째는 사용자가 원하는 그러나 많은 셀을 선택할 수 있지만, 두 번째 및 세 번째로, 하나에 국한됩니다.
문제점 : 셀을 선택한 다음 다른 셀을 선택할 때마다 작동합니다. 첫 번째 셀을 선택하면 두 셀 모두 확인됩니다.
나는 도움이나 제안을 주시면 감사하겠습니다. 감사!
고마워, 나는 그것을 돌려 줄 것이다 ... 내가 다시로드해야합니까? – user2242965
@ user2242965 예, 변경 사항을 보려면 데이터를 다시로드해야합니다 (또는 reloadRowsAtIndexPaths를 사용할 수 있지만 좀 더 많은 코드가 필요하면보다 효율적으로 사용하고 싶을 수도 있습니다). – rdelmar
흠 ... 좋아, 고마워, 지금 이걸 시도해 볼게. – user2242965