title: Getting text from UIAlertView
body: <p>I'm trying to get text from an alert view and add it to my mutable array to list in a table view. I realize there is a similar question that was posted a few months ago, but I dont understand how to utilize the given answer. </p>
  
  <pre><code>-(IBAction)insert {
      UIAlertView* dialog = [[UIAlertView alloc] init];
      [dialog setDelegate:self];
      [dialog setTitle:@"Enter Name"];
      [dialog setMessage:@" "];
      [dialog addButtonWithTitle:@"Cancel"];
      [dialog addButtonWithTitle:@"OK"];
  
      UITextField *nameField = [[UITextField alloc] initWithFrame:CGRectMake(20.0, 45.0, 245.0, 25.0)];
      [nameField setBackgroundColor:[UIColor whiteColor]];
      [dialog addSubview:nameField];
      [dialog show];
  
      [data addObject:[nameField text]];
      [mainTableView reloadData];
  </code></pre>
  
  <p>However my app crashes because it says I'm attempting to insert a nil object at index 0. What am I doing wrong?</p>
  
  <p>EDIT: Ok I think I'm missing a method to handle the alertview. So I found this:</p>
  
  <pre><code>- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex {
      NSString *buttonTitle=[alertView buttonTitleAtIndex:buttonIndex];
      if([buttonTitle isEqualToString:@"Cancel"]) {
          return;
      }
      else if([buttonTitle isEqualToString:@"Ok"]) {
          [data addObject:nameField.text];
  
      }
  </code></pre>
  
  <p>Now I just need to connect the pieces, but not sure how.</p>