gpt4 book ai didi

ios - 我如何删除表格中的单元格数组

转载 作者:行者123 更新时间:2023-11-29 04:54:50 25 4
gpt4 key购买 nike

我在从表中删除行时遇到问题。我有一个表单元格类和一个 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)以纠正删除行?

最佳答案

您还必须从数据源中删除该单元格。

关于ios - 我如何删除表格中的单元格数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8212388/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com