我想通過添加一個按鈕插入和刪除數據,當我點擊我的按鈕查詢的作品,但數據一次不插入或刪除我必須重新啓動應用程序來查看插入或刪除的行在我的tableView,我還添加了的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];
}
}
這裏的代碼 一些和平是從哪兒IM添加或刪除行我的按鈕在收藏夾
- (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];
}
}
是這將是btn? –
是在btn行動事件的隊友只是使用此代碼,請參閱我在你的btn行動事件中添加一些行.. –