언제든지 확인할 수있는 항목을 최대 3 개까지만 저장합니다.UITableViewCell 액세서리 체크 표시가 행 선택 후 스크롤되지 않음
나는에 그런 didSelectRowAtIndexPath
에 selectedRowDictionary
를라는 NSMutabeDictionary
에서 선택한 행을 저장 내 cellForRowAtIndexPath
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"identifer" forIndexPath:indexPath];
if (_selectedRowDictionary && [_selectedRowDictionary count]) {
for (NSString *rowSelected in _selectedRowDictionary) {
BOOL isRowSelected = [[_selectedRowDictionary valueForKey:rowSelected] integerValue];
if (isRowSelected){
NSLog(@"rowSelected: %@", rowSelected);
} else {
NSLog(@"rowNotSelected: %@", rowSelected);
}
int rowIndexSelected = [[rowSelected substringFromIndex:[rowSelected length] - 1 ] integerValue];
if (isRowSelected && rowIndexSelected == indexPath.row) {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
} else {
cell.accessoryType = UITableViewCellAccessoryNone;
}
}
}
return cell;
}
- - didSelectRowAtIndexPath:
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
if (cell.accessoryType == UITableViewCellAccessoryCheckmark) {
cell.accessoryType = UITableViewCellAccessoryNone;
if (_selectedRowDictionary) {
[_selectedRowDictionary removeObjectForKey:[NSString stringWithFormat:@"row%d", indexPath.row]];
NSLog(@"row %d removed from array", indexPath.row);
}
} else {
cell.accessoryType = UITableViewCellAccessoryCheckmark;
[_selectedRowDictionary setValue:[NSNumber numberWithBool:YES] forKey:[NSString stringWithFormat:@"row%d", indexPath.row]];
}
if ([_selectedRowDictionary count] > 3) {
UITableViewCell *lastSelectedCell = [tableView cellForRowAtIndexPath:indexPath];
lastSelectedCell.accessoryType = UITableViewCellAccessoryNone;
[_selectedRowDictionary removeObjectForKey:[NSString stringWithFormat:@"row%d", indexPath.row]];
NSLog(@"row selected > 3, row%d not selected", indexPath.row);
}
}
가 나는 원인이 뭔가를 놓치고 있습니까 내가 아래로 스크롤 할 때 셀이 다시 선택 취소됩니다. 그는 tableview?
나는 사전을 NSLog
'NSMutableArray'에 대한 표시 인터페이스가 없습니다. 선택기 removeObjectIndexPath'가 선언 되었습니까? 'removeObjectAtIndex : indexPath.row'를 원하셨습니까? – Simon
콜론을 놓쳤습니다. 내 대답을 업데이트했습니다. – norders
감사! 이것은 이전의 시도에서 무엇이 잘못 되었는가를 알고 있습니까? – Simon