0
我有从表中删除行的问题。我有一个单元格的表和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"];
[email protected]"+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)纠正删除行?
这个例外是什么意思? – dasdom