title: "Attempt to insert row 0 into section 0, but there are only 0 rows in section 0 after the update" Error
body: <p>I have an app that is selecting a person from their contacts list and takes their First name, last name and email. It then saves the first name to a nsmutablearray and puts it into a uitableview cell. My problem occurs once the contact is selected in the simulator.</p>
  
  <p>Code:</p>
  
  <p>.h:</p>
  
  <pre><code>#import &lt;UIKit/UIKit.h&gt;
  #import &lt;AddressBookUI/AddressBookUI.h&gt;
  
  @interface FirstViewController : UIViewController &lt;    ABPeoplePickerNavigationControllerDelegate, UITableViewDelegate, UITableViewDataSource&gt;
  
  - (IBAction)showPicker:(id)sender;
  
  @property (weak, nonatomic) IBOutlet NSString *firstName;
  
  @property (weak, nonatomic) IBOutlet NSString *email;
  
  @property (weak, nonatomic) IBOutlet NSString *lastName;
  
  
  @property (weak, nonatomic) IBOutlet UITableView *myTableView;
  
  @property (strong, nonatomic) NSMutableArray *contacts;
  
  @end
  </code></pre>
  
  <p>.m:</p>
  
  <pre><code>#import "FirstViewController.h"
  
  @interface FirstViewController ()
  
  @end
  
  @implementation FirstViewController
  
  @synthesize firstName;
  
  @synthesize email;
  
  @synthesize lastName;
  
  @synthesize contacts;
  
  @synthesize myTableView;
  
  
  - (void)viewDidLoad
  {
      [super viewDidLoad];
      // Do any additional setup after loading the view, typically from a nib.
      contacts = [[NSMutableArray alloc]initWithObjects:nil];
  }
  
  - (void)didReceiveMemoryWarning
  {
      [super didReceiveMemoryWarning];
      // Dispose of any resources that can be recreated.
  }
  
  #pragma mark - UITableView Datasource
  
  -(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  {
      return 1;
  } 
  
  -(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      return contacts.count;
  }
  
  -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath  *)indexPath
  {
      static NSString *cellIdentifier = @"Cell";
  
      UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
  
      if (cell == nil) {
          cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault  reuseIdentifier:cellIdentifier];
  
      }
  
      cell.textLabel.text = [contacts objectAtIndex:indexPath.row];
  
      return cell;
  }
  
  - (IBAction)showPicker:(id)sender {
  
      ABPeoplePickerNavigationController *picker =
      [[ABPeoplePickerNavigationController alloc] init];
      picker.peoplePickerDelegate = self;
  
      [self presentModalViewController:picker animated:YES];
  }
  
  - (void)peoplePickerNavigationControllerDidCancel:
  (ABPeoplePickerNavigationController *)peoplePicker
  {
      [self dismissModalViewControllerAnimated:YES];
  }
  
  
  - (BOOL)peoplePickerNavigationController:
  (ABPeoplePickerNavigationController *)peoplePicker
        shouldContinueAfterSelectingPerson:(ABRecordRef)person {
  
      [self displayPerson:person];
      [self dismissModalViewControllerAnimated:YES];
  
      return NO;
  }
  
  - (BOOL)peoplePickerNavigationController:
  (ABPeoplePickerNavigationController *)peoplePicker
        shouldContinueAfterSelectingPerson:(ABRecordRef)person
                                  property:(ABPropertyID)property
                                identifier:(ABMultiValueIdentifier)identifier
  {
  
  
  
  
  
      return NO;
  
  }
  
  
  - (void)displayPerson:(ABRecordRef)person
  {
      NSString* name = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                                                      kABPersonFirstNameProperty);
      self.firstName = name;
  
      NSString* last = (__bridge_transfer NSString*)ABRecordCopyValue(person,
                                                                      kABPersonLastNameProperty);
      self.lastName = last;
  
  
      ABMultiValueRef  emails = ABRecordCopyValue(person, kABPersonEmailProperty);
      NSString *emailId = (__bridge NSString *)ABMultiValueCopyValueAtIndex(emails, 0);//0     for "Home Email" and 1 for "Work Email".
  
      self.email = emailId;
  
      if (!(contacts))
      {
  
          contacts = [[NSMutableArray alloc]init];
  
      }
  
      [contacts insertObject:firstName atIndex:0];
  
      NSIndexPath * indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
  
      [self.myTableView insertRowsAtIndexPaths:@[indexPath]  withRowAnimation:UITableViewRowAnimationAutomatic];
  }
  
  
  
  
  @end
  </code></pre>