按下后如何保存选定的按钮状态?因此,当您在视图控制器之间切换并来到原始视图控制器时,按钮保持按下状态,直到您再次按下它...
- (void)viewDidLoad
{
[super viewDidLoad];
addCheck = NO;
favCheck = NO;
}
- (IBAction)listButton:(id)sender {
UIImage *removeListImage = [UIImage imageNamed:@"removeList.png"];
UIImage *addListImage = [UIImage imageNamed:@"addList.png"];
NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults];
NSMutableArray *favoriteviews = [defaults mutableArrayValueForKey:@"favorite_views_key"];
[defaults setObject:favoriteviews forKey:@"favorite_views_key"];
[defaults synchronize];
if (!addCheck) {
[addList setImage:removeListImage forState:UIControlStateNormal];
addCheck = YES;
[favoriteviews addObject:@"Apple"];
[favoriteviews addObject:@"Banana"];
[favoriteviews addObject:@"Celery"];
}
else if (addCheck) {
[addList setImage:addListImage forState:UIControlStateNormal];
addCheck = NO;
[favoriteviews removeObject:@"Apple"];
[favoriteviews removeObject:@"Banana"];
[favoriteviews removeObject:@"Celery"];
}
}