Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按“在单元格中重新加载UItableView”按钮_Uitableview_Reloaddata - Fatal编程技术网

按“在单元格中重新加载UItableView”按钮

按“在单元格中重新加载UItableView”按钮,uitableview,reloaddata,Uitableview,Reloaddata,我想在按下uicellview中的按钮时重新加载uitableview。为了清楚起见,我正在做的是,我在cellTableView上创建了一个收藏夹按钮,当我第一次按下它时,它会打开,星光灯会亮起,当我再次按下它时,它会关闭,星光灯会熄灭,当它是1->Favorited或on时,当它是0->not Favorited或off时,我会在sqlite中保存开和关值。 我的问题是,当我按下星号按钮时,sqlite中的值正在更改,但星号的图像没有更改 这是我的密码 - (void)viewDidLoad

我想在按下uicellview中的按钮时重新加载uitableview。为了清楚起见,我正在做的是,我在cellTableView上创建了一个收藏夹按钮,当我第一次按下它时,它会打开,星光灯会亮起,当我再次按下它时,它会关闭,星光灯会熄灭,当它是1->Favorited或on时,当它是0->not Favorited或off时,我会在sqlite中保存开和关值。 我的问题是,当我按下星号按钮时,sqlite中的值正在更改,但星号的图像没有更改

这是我的密码

- (void)viewDidLoad
{
 [super viewDidLoad];

[self retrieveDataFromSqlite:1];
}


-(sqlite3 *) openDataBase{

sqlite3 *database;

NSString* docPath = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) lastObject];
NSString* dbPath = [docPath stringByAppendingPathComponent:@"HealthyTips.sqlite"];

NSLog(@"dbPath: %@",dbPath);

if (sqlite3_open([dbPath UTF8String], &database) != SQLITE_OK) {
    NSLog(@"Failed to open database!");
}else{
    NSLog(@"database opened!");
}

return database;
 }


-(void) retrieveDataFromSqlite:(int)num {

tipsArray = [[NSMutableArray alloc] init];

sqlite3 *myDatabase = [self openDataBase];

    const char *sqlSelect  = "select * from tips_table";

    if (num == 1) {
       // sqlSelect = "select * from tips_table";
    } else if (num == 2){

    }else{

    }

    sqlite3_stmt *compiledStatement;

    if(sqlite3_prepare_v2(myDatabase, sqlSelect, -1, &compiledStatement, NULL) == SQLITE_OK) {

        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {

            int tips_id = sqlite3_column_int(compiledStatement, 0);

            NSString *tips_content = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 1)];

            NSString *tips_favorite = [NSString stringWithUTF8String:(char *) sqlite3_column_text(compiledStatement, 2)];

            Tips *tips = [[Tips alloc] initWithUniqueId:tips_id tips_content:tips_content tips_favorite:tips_favorite];

            [tipsArray addObject:tips];


        } // while end

    }// prepare end


    sqlite3_finalize(compiledStatement);

sqlite3_close(myDatabase);


 }


-(void) updateFavoriteTip:(NSString *)tipFavorite tipID:(int)tipID {

sqlite3 *myDatabase = [self openDataBase];

sqlite3_exec(myDatabase, [[NSString stringWithFormat:@"UPDATE tips_table set tip_favorites = '%@' WHERE _id = '%d' ", tipFavorite, tipID] UTF8String], NULL, NULL, NULL);


 }

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}


- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
// Return the number of sections.
return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
// Return the number of rows in the section.
return [tipsArray count];
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"tipCell";

TipsTableCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];


if (!cell) {
    cell = [[TipsTableCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
}

Tips *temp= (Tips *)[self.tipsArray objectAtIndex:indexPath.row];

[cell.tipsContent setText:[NSString stringWithFormat:@"%@",temp.tips_content]];

[cell.tipsContent setFont:[UIFont fontWithName:@"Bauhaus Md BT" size:20]];

if ([temp.tips_favorite isEqualToString:@"1"]) {

    [cell.favoriteImage setImage:[UIImage imageNamed:@"tips_star_on.png"] forState:UIControlStateNormal];

}else{

  [cell.favoriteImage setImage:[UIImage imageNamed:@"tips_star_off.png"] forState:UIControlStateNormal];
}

[cell.favoriteImage addTarget:self action:@selector(setFavoriteTip:)
        forControlEvents:UIControlEventTouchUpInside];

cell.favoriteImage.tag = indexPath.row;

UIImageView *av = [[UIImageView alloc] initWithFrame:CGRectMake(20, 20, 277, 58)];
av.backgroundColor = [UIColor clearColor];
av.opaque = NO;
av.image = [UIImage imageNamed:@"pattern_gray0.png"];
cell.backgroundView = av;


cell.selectedBackgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"background_color.png"]];

return cell;
}

-(IBAction)setFavoriteTip:(UIButton *)sender{

int tag = sender.tag;

Tips *temp= (Tips *)[self.tipsArray objectAtIndex:tag];

NSLog(@"in setFavoriteTip, favorite: %@ - id: %d",temp.tips_favorite, temp.tips_id);

if ([temp.tips_favorite isEqualToString:@"1"]) {

    [self updateFavoriteTip:@"0" tipID:temp.tips_id];

}else{
    [self updateFavoriteTip:@"1" tipID:temp.tips_id];

}

// reloads the table well but the image of star not changing.
[self.tableView reloadData];

}
希望有人能帮助我