У меня есть сгруппированный UITableView с 3 разделами: 2 из 3 - это константы (каждая с единственной ячейкой, которая не изменяется) и первый раздел, который вы можете добавить или удалить из ячеек. все работает отлично, кроме того, что при удалении ячеек из этого раздела: как только я удалил последнюю ячейку, эта ячейка исчезает (как и ожидалось), но затем другие секции не работают, то есть я не могу щелкнуть по ним (они оба загружают другое представление). если я загружаю приложение, когда первый раздел пуст, то все в порядке. это происходит только после удаления последней ячейки в этом разделе. я попытался поместить логи везде в коде, и все выглядит хорошо.
Буду признателен за любое предложение.
Вот код, который может иметь отношение к делу. рады предоставить больше, если это необходимо:
- (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;
}
}
ОБНОВЛЕНИЕ: добавление дополнительных методов:
- (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];
}