Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //This is one view.
- -(void)saveInfo:(NSArray*)myArray
- {
- [[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"array"];
- }
- - (IBAction)storeBeers:(id)sender {
- //onclick store beers
- NSString *amountOfBeers = beerAmountTextField.text;
- NSString *personOneName = personOneTextField.text;
- NSString *personTwoName = personTwoTextField.text;
- NSArray *beers = [NSArray arrayWithObjects:amountOfBeers,personOneName,personTwoName,nil];
- [self saveInfo:beers];
- NSLog (@"Number of beers the user wants to drink = %@", beers);
- }
- //This is the other.
- -(NSArray *)getArray
- {
- //this function gets the saved array
- NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"array"];
- return array;
- }
- - (void)viewDidLoad
- {
- //assign the total beers to a labe on the view.
- NSArray *array = [self getArray];
- totalBeerLabel.text = array[0];
- //turn the string into an int
- totalBeersToBeDrunk = [array[0] intValue];
- //assign names to labels.
- personOneName.text =array[1];
- personTwoName.text =array[2];
- [super viewDidLoad];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement