title: How add values from text field / label to an array when a button click in iphone
body: <p>I have a text field In that user can enter values from 1-10</p>
  
  <p>at the bottom of the text field i have button.</p>
  
  <p>i need to add the values in text filed to array when user clicks done button </p>
  
  <p>for this i wrote code like this.</p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      PainlevelsArray = [[NSMutableArray alloc] init]; //PainlevelsArray declared in .h
  
  }
  
  
  -(IBAction)doneClick:(id)sender
  {
      [PainlevelsArray addObject:txtField.text ];
  
      // [PainlevelsArray insertObject:rateLabel.text atIndex:0 ];
      NSLog(@"PainlevelsArray *** %@",PainlevelsArray);
  
     [self.navigationController popToRootViewControllerAnimated:YES];
  
  }
  </code></pre>
  
  <p>But every time array displays only the recently added one value only in log when button clicks, like this</p>
  
  <p><em><strong>Output on Console</em></strong></p>
  
  <p>========================</p>
  
  <pre><code>2012-05-07 10:11:15.689 ESPT[796:10d03] PainlevelsArray *** (
      2
  )
  2012-05-07 10:11:27.984 ESPT[796:10d03] PainlevelsArray *** (
      4
  )
  </code></pre>
  
  <p><em><strong><code>My array gets empty every time view loads, and adde a fresh entry when button clicks</code></em></strong>
  But i need like this</p>
  
  <pre><code>2012-05-07 10:11:27.984 ESPT[796:10d03] PainlevelsArray *** (
          4,
          5,
          2,
          6,
          8,
      )
  </code></pre>
  
  <p>All the velues enters are adde/inserted to the existing array.</p>
  
  <p>Thanks in advance</p>
  
  <p><strong>in ExerciseStartViewController</strong></p>
  
  <pre><code>-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
   ExerciseResult *result = [[ExerciseResult alloc] init];
              [self.navigationController pushViewController:result animated:YES];
              [result release];
      }
  </code></pre>
  
  <p><strong>in current/ ExerciseResult viewcontroller</strong></p>
  
  <pre><code>- (void)viewDidLoad
  {
      [super viewDidLoad];
      PainlevelsArray = [[NSMutableArray alloc] init]; //PainlevelsArray declared in .h
  
  }
  
  
  -(IBAction)doneClick:(id)sender
  {
      [PainlevelsArray addObject:txtField.text ];
  
      // [PainlevelsArray insertObject:rateLabel.text atIndex:0 ];
      NSLog(@"PainlevelsArray *** %@",PainlevelsArray);
  
     [self.navigationController popToRootViewControllerAnimated:YES];
  
  }
  </code></pre>