Я храню не более трех предметов, которые разрешено проверять в любое время.Маркировка аксессуаров UITableViewCell не сохраняется при прокрутке после выбора строки
хранить выбранные строки в качестве NSMutabeDictionary
называемых selectedRowDictionary
в didSelectRowAtIndexPath
Тогда в моем 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);
}
}
Могу ли я что-то отсутствует, что вызывает ячейку, которую нужно отменить, когда я прокручиваю вниз он настольный?
Когда я NSLog
словаря, он говорит, что эти строки существуют, и были выбраны
Я проверил подобные вопросы, но я думал, что решается вопрос утилизации клеток уже.
Я получаю 'Нет видимого интерфейса для 'NSMutableArray' объявляет селектор removeObjectIndexPath'? Вы имели в виду 'removeObjectAtIndex: indexPath.row'? – Simon
Я пропустил двоеточие. Обновил мой ответ. – norders
Спасибо! Это фиксировало это (: знаете ли вы, что было не так с моей предыдущей попыткой? – Simon