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