I have to squares on the first view controller its hidden at anytime and when the app launches you have two button white and black. when the user presses on either button and press on back to view 1 it shows either the white square and black square depending on which the user picked.
code below:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidAppear:(BOOL)animated {
NSUserDefaults *SetBlack = [NSUserDefaults standardUserDefaults];
blacksquare.hidden = [SetBlack boolForKey:@"black"];
NSUserDefaults *SetWhite = [NSUserDefaults standardUserDefaults];
whitesquare.hidden = [SetWhite boolForKey:@"white"];
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
and
#import "SecondViewController.h"
@interface SecondViewController ()
@end
@implementation SecondViewController
- (IBAction)black:(id)sender{
NSUserDefaults *SetBlack = [NSUserDefaults standardUserDefaults];
[SetBlack setBool:NO forKey:@"black"];
}
- (IBAction)white:(id)sender{
NSUserDefaults *SetWhite = [NSUserDefaults standardUserDefaults];
[SetWhite setBool:NO forKey:@"black"];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
/*
#pragma mark - Navigation
// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
// Get the new view controller using [segue destinationViewController].
// Pass the selected object to the new view controller.
}
*/
@end