У меня есть сгруппированный UITableView с тремя разделами: 2 из 3 являются константами (каждая из которых имеет только одну ячейку, которая не изменяется), и первый раздел, который вы можете добавить или удалить из клетки. все работает отлично, кроме того, при удалении ячеек из этого раздела: после того, как я удалил последнюю ячейку, эта ячейка исчезнет (как и ожидалось), но тогда другие разделы не будут работать, то есть я не могу нажать на них (они оба загружают другое представление). если я загружаю приложение, когда первый раздел пуст в первую очередь, все в порядке. это происходит только после удаления последней ячейки в этом разделе. я попытался поместить журналы везде в коде, и все выглядит нормально.Ячейки UITableView не выбраны после удаления последней ячейки
Поблагодарили бы за любые предложения.
Вот несколько кодов, которые могут иметь значение. рады предоставить более, если это необходимо:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.section == 0) {
return YES;
} else {
return NO;
}
}
- (void)tableView:(UITableView *)aTableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[tblSimpleTable beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete) {
NSMutableArray * section = [listOfItems objectAtIndex:indexPath.section];
[section removeObjectAtIndex:indexPath.row];
//UPDATING USERS DEFAULTS
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
[defaults setObject:section forKey:@"listOfAccessNumbers"];
[tblSimpleTable deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationRight];
[tblSimpleTable reloadData];
}
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
...
}
[tblSimpleTable endUpdates];
}
- (void)setEditing:(BOOL)editing animated:(BOOL)animated {
NSLog(@"****************** entering setEditing");
[super setEditing:editing animated:animated];
[tblSimpleTable setEditing:editing animated:YES];
if (editing) {
editButton.enabled = NO;
} else {
editButton.enabled = YES;
}
}
UPDATE: добавление нескольких методов:
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSLog(@"****************** entering cellForRowAtIndexPath");
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier]; //try here diff styles
}
NSArray *array = [[NSArray alloc] init];
array = [listOfItems objectAtIndex:indexPath.section];
NSString *cellValue = [array objectAtIndex:indexPath.row];
cell.textLabel.text = cellValue;
cell.textLabel.font = [UIFont systemFontOfSize:14];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
cell.textLabel.textColor = [UIColor colorWithRed:.196 green:0.3098 blue:0.52 alpha:1.0];
if (sectionIndicator == YES){
if (indexPath.section == 0) {
cell.accessoryType = UITableViewCellAccessoryNone;
}
else if (indexPath.section == 1) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
else
{
if (indexPath.section == 0) {
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
else if (indexPath.section == 1) {
cell.selectionStyle = UITableViewCellSelectionStyleNone;
}
}
return cell;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return [listOfItems count];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[listOfItems objectAtIndex:section] count];
}
Правильно ли вы обрабатываете регистр в методах 'numberOfSectionsInTableView:' и 'tableView: numberOfRowsInSection:'? – msgambel
Для метода commitEditingStyle вам необязательно нужны 'beginUpdates' и' endUpdates'. Было бы целесообразно удалить их и посмотреть, устраняет ли проблема проблему. Если это не так, проблема скорее всего связана с вашим методом tableView: cellForRowAtIndexPath: или одним из методов dataSource, поскольку это происходит после обновления таблицы – justin
да, но я тоже не уверен, что понимаю соединение, потому что таблица рисуется правильно (3 секции, одна «пустая» без ячеек и две секции (фиксированные) с одной ячейкой каждый). – TommyG