我想通过添加一个按钮来插入和删除数据,当我单击我的按钮查询有效但数据没有立即插入或删除我必须重新启动应用程序才能在我的 tableView 中查看插入或删除的行,我还添加了 tableView 重新加载数据,但它在这里不起作用是这个视图中的一些和平代码我想插入或删除行
- (void)viewDidLoad
{
[super viewDidLoad];
isLoadingAlphabets=1;
DBHandler *obj= [[DBHandler alloc]init];
Array = [obj loadFavoriteWords];
isSearching = 0;
displayItems = [[NSMutableArray alloc] initWithArray:Array];
// Do any additional setup after loading the view, typically from a nib.
[tableview reloadData];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)dealloc {
[tableview release];
[super dealloc];
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(isSearching){
return [displayItems count];
}
else {
NSLog(@"Count: %d", [Array count]);
return [Array count];
}
}
这是我在收藏夹中添加或删除行的按钮
- (void)viewDidLoad
{
[super viewDidLoad];
DBHandler* db=[[DBHandler alloc]init];
// NSLog(@"asas%@",detail_word);
if(![db isAlreadyInFavorites:word_id])
{
[btnFavorite setImage:[UIImage imageNamed: @"star-grey.png" ] forState:UIControlStateNormal];
} else {
[btnFavorite setImage:[UIImage imageNamed:@"star-yellow.png"] forState:UIControlStateNormal ];
}
// Do any additional setup after loading the view from its nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)btn:(id)sender {
DBHandler *db = [[DBHandler alloc]init];
if(![db isAlreadyInFavorites:word_id]){
[btnFavorite setImage:[UIImage imageNamed:@"star-yellow.png"] forState:UIControlStateNormal];
[db addFavoriteWord:word_id];
}
else{
[db deleteFavoriteWord:word_id];
[btnFavorite setImage:[UIImage imageNamed:@"star-grey.png"] forState:UIControlStateNormal];
}
}