У меня проблема с удалением строк из таблицы. У меня есть класс для ячейки таблицы и базы данных SQL. Затем я загружаю таблицу из базы данных и делаю что-то с ней. Теперь, когда я пытаюсь удалить строки по индексным путям, у меня возникает исключение.
- (void)viewDidLoad
{
[super viewDidLoad];
databasecontroller=((SexyGirlsWeatherAppDelegate *)[[UIApplication sharedApplication] delegate]).databasecontroller;
self.favorites=[databasecontroller select:@"SELECT Name, id FROM Favorites"];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
cell = (CustomCell *)[favoritesTableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:self options:nil];
cell = [nib objectAtIndex:0];
}
[favoritesTableView setBackgroundColor:[UIColor clearColor]];
cell.name.text = [[favorites objectAtIndex:indexPath.row] objectForKey:@"Name"];
cell.currenttemp.text=@"+45 C";
cell.currentweather.image=[UIImage imageNamed:@"sunny"];
//[cell.selectcell setBackgroundImage:[UIImage imageNamed:@"selectfalse"] forState:UIControlStateNormal];
cell.razdelitel.image=[UIImage imageNamed:@"delenie"];
if(editModeOn==YES) [cell EditModeON];
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if(editModeOn==YES)
{
int existcount=0;
for(int z=0; z<[selectrowsarray count];z++)
{
if([selectrowsarray objectAtIndex:z]==indexPath) // check for exist of item
{
[selectrowsarray removeObjectAtIndex:z];
existcount++;
}
}
if(existcount==0)
{
[selectrowsarray addObject:indexPath];
}
}
}
-(IBAction) deleteSelectedTownsFromFavorites:(id)sender // here i try to delete cells
{
// [favoritesTableView beginUpdates];
// [databasecontroller exec:[NSString stringWithFormat:@" DELETE FROM Favorites WHERE Id=%d", 3]];
// [favoritesTableView reloadData];
// [databasecontroller exec:@"UPDATE Favorites"];
// for(int t=0; t<[selectrowsarray count];t++)
// {
//
[favorites removeLastObject];
[favoritesTableView deleteRowsAtIndexPaths:selectrowsarray withRowAnimation:UITableViewRowAnimationMiddle];
// }
optionsview.hidden=true;
// [favoritesTableView endUpdates];
}
- (NSInteger)tableView:(UITableView *)favoritesTableView numberOfRowsInSection:(NSInteger)section
{
//return [favorites count];
return [favorites count];
}
Как я могу синхронизировать 2 массива (из базы данных и из selectcelladdresses) для исправления удаления строк?