0

画像を変更することはできますが、このビューに戻ると、UIControlStateSelectedを使用していたときのUIControlStateNormalと同じ画像が表示されます。

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

    AppDelegate *obj=[[UIApplication sharedApplication]delegate];

    if ([sender isSelected]) {

        [sender setImage:[UIImage imageNamed:@"favrtes_uncheck.png"] forState:UIControlStateNormal];
        [sender setSelected:NO];

        NSMutableArray* array = [[[NSUserDefaults standardUserDefaults] objectForKey:@"favoriteItems"] mutableCopy];
        [array removeObject:[NSNumber numberWithInt:self.number]];

        [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"favoriteItems"];

        NSLog(@"%@", array);

        obj.country_main= array;
    } else 
    {
        [sender setImage:[UIImage imageNamed:@"favrtes_detail.png"] forState:UIControlStateSelected];
        [sender setSelected:YES];

        NSMutableArray* array= [[[NSUserDefaults standardUserDefaults] objectForKey:@"favoriteItems"] mutableCopy];

        [array addObject:[NSNumber numberWithInt:self.number]];

        [[NSUserDefaults standardUserDefaults] setObject:array forKey:@"favoriteItems"];

        NSLog(@"%@", array);

        obj.country_main= array;
    }
}
4

1 に答える 1