Advertisement
wkerswell

Untitled

Sep 26th, 2012
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. //This is one view.
  2.  
  3.  
  4.  
  5. -(void)saveInfo:(NSArray*)myArray
  6. {
  7.     [[NSUserDefaults standardUserDefaults] setObject:myArray forKey:@"array"];
  8.    
  9. }
  10.  
  11.  
  12. - (IBAction)storeBeers:(id)sender {
  13.     //onclick store beers
  14.     NSString *amountOfBeers = beerAmountTextField.text;
  15.     NSString *personOneName = personOneTextField.text;
  16.     NSString *personTwoName = personTwoTextField.text;
  17.     NSArray  *beers = [NSArray arrayWithObjects:amountOfBeers,personOneName,personTwoName,nil];
  18.     [self saveInfo:beers];
  19.     NSLog (@"Number of beers the user wants to drink = %@", beers);
  20.    
  21. }
  22.  
  23.  
  24.  
  25. //This is the other.
  26.  
  27.  
  28. -(NSArray *)getArray
  29. {
  30.     //this function gets the saved array
  31.     NSArray *array = [[NSUserDefaults standardUserDefaults] objectForKey:@"array"];
  32.     return array;
  33. }
  34.  
  35.  
  36. - (void)viewDidLoad
  37. {
  38.     //assign the total beers to a labe on the view.
  39.     NSArray *array = [self getArray];
  40.     totalBeerLabel.text = array[0];
  41.    
  42.     //turn the string into an int
  43.     totalBeersToBeDrunk = [array[0] intValue];
  44.    
  45.     //assign names to labels.
  46.     personOneName.text =array[1];
  47.     personTwoName.text =array[2];
  48.    
  49.     [super viewDidLoad];
  50.    
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement