title: tableView:numberOfRowsInSection: called twice in a row
body: <p>I'm getting an error:</p>
  
  <blockquote>
    <p>Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of rows in section 0.</p>
  </blockquote>
  
  <p>because I'm adding an object to one instance of an array, but then reloading the table view from another instance of what is supposed to be the same array. How can I create a single instance of the array and just pass it around from class to class? I can do it easily in java, but in Objective-C you can't make static variables so I'm not sure how to do this.</p>
  
  <p>EDIT: more code.<br>
  Here is a method from another class that is called in order to save a file. I'm using Core Data, so first it adds the file to the context (model), then to the array, then it saves the context. This method is in a class called 'Player'</p>
  
  <pre><code>-(BOOL)saveRecording {
      Bank *B = [MusikerViewController daBank];
      AudioTableViewController *ATVC2 = [MusikerViewController ATVControl];
      NSLog(@"Place A");
     AudioFile *myAudioFileMusicX314 = [[B addAudioFileEntityToModelWithDate:myDate andURLString:strPath] retain];
      NSLog(@"Place B");
  
      myAudioFileMusicX314.type = true;
  
      [ATVC2 addAudioEntityToArray:myAudioFileMusicX314];
      NSLog(@"Place C ***********************************************");
  
      if(![B saveContext]) { //save context after adding file to keep consistancy
          NSLog(@"addAudioFileEntityToModel is returning a nil managedObjectContext");
          return NO;
      }
      NSLog(@"Place D");
  
      [myDate release];
      [strPath release];
      [myAudioFileMusicX314 release];
      [ATVC2 release];
      NSLog(@"Place E");
  
      return YES;
  
  }
  </code></pre>
  
  <p>The following method is in the class that contains the table view--its caled AudioTableViewController</p>
  
  <pre><code>    -(void)addAudioEntityToArray:(AudioFile *)event {
      NSIndexPath *indexPath;
  
      if(event.type) {
          [[MusikerViewController recordingsArray] addObject:event];//self?
          indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
      }
  
      else {
          [[MusikerViewController downloadsArray] addObject:event];
          indexPath = [NSIndexPath indexPathForRow:0 inSection:1];
      }
  
      [[self tableView] setEditing:YES animated:NO];
     [self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
                            withRowAnimation:UITableViewRowAnimationNone];
  
  }
  </code></pre>
  
  <p>The following method adds the object to my model</p>
  
  <pre><code>- (AudioFile *)addAudioFileEntityToModelWithDate:(NSDate *)theD andURLString:(NSString *)str {
      NSLog(@"addAudio...WithDate -- called");
      sound = (AudioFile *)[NSEntityDescription insertNewObjectForEntityForName:@"AudioFile" inManagedObjectContext:managedObjectContext];
  
      sound.creationDate = theD;
      sound.soundPath = str; //set the sound path to the sound file's url
      [self alertForTitle];
  
      NSLog(@"No problems yet at place D - addaudio...String, sound title is %@", sound.title);
      NSLog(@"Context at addAudioFileEntityToModel is: %@", managedObjectContext);
  
      return sound;
  }
  </code></pre>
  
  <p>here is the important parts of MusikViewController.h -- it keeps track of recordingsArray and downloadsArray</p>
  
  <pre><code>@interface MusikerViewController : UIViewController {
  }
  
  NSMutableArray   *recordingsArray;
  NSMutableArray   *downloadsArray;
  
  + (NSMutableArray *)recordingsArray;
  + (NSMutableArray *)downloadsArray;
  </code></pre>
  
  <p>and MusikViewController.m</p>
  
  <pre><code> + (NSMutableArray *)recordingsArray {
      NSLog(@"recordingsArray called");
  
      if(!recordingsArray) {
          recordingsArray = [[NSMutableArray alloc] init];
          NSMutableArray *bigTempArray = [[[[Bank alloc] init] autorelease] getFetchArray]; //change this
          for(AudioFile *af in bigTempArray)
              if(af.type) {
                  [recordingsArray addObject:af];
              }
          NSLog(@"recordingsArray exists");
      }
      return recordingsArray;
  }
  
  + (NSMutableArray *)downloadsArray {
      NSLog(@"recordingsArray called");
  
      if(!downloadsArray) {
          downloadsArray = [[NSMutableArray alloc] init];
          // if(!bigTempArray)
          NSMutableArray *bigTempArray = [[[[Bank alloc] init] autorelease] getFetchArray];
          for(AudioFile *af in bigTempArray)
              if(!af.type) {
                  [downloadsArray addObject:af];
              }
      }
      return downloadsArray;
  }
  </code></pre>
  
  <p>and some AudioTableViewController methods</p>
  
  <pre><code>- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
  {
      // Return the number of rows in the section.
      NSLog(@"Place F");    
  
      if(section == 0) {
      return [[MusikerViewController recordingsArray] count];
      }
      else if (section == 1) {
          return [[MusikerViewController downloadsArray] count];
      }
  
  }
  
       - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
      {
  
          static NSString *CellIdentifier = @"Cell";
  
          UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
          if (!cell) {
              cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease];
          }
  
          AudioFile *event;
          if(indexPath.section == 0) {
          event = (AudioFile *)[[MusikerViewController recordingsArray] objectAtIndex:indexPath.row];
          } else if (indexPath.section == 1) {
              NSLog(@"downAry indexPath caled at cellForRow...Path");
              event = (AudioFile *)[[MusikerViewController downloadsArray] objectAtIndex:indexPath.row];
          }
          cell.accessoryType = UITableViewCellAccessoryDetailDisclosureButton;
          if(event.title) {
          cell.detailTextLabel.text = [Player dateString:event.creationDate];
          cell.textLabel.text = event.title;
          } else {
              cell.textLabel.text = [Player dateString:event.creationDate];
              cell.detailTextLabel.text = nil;
          }
  
          return cell;
      }
  
  
              - (void)viewDidLoad //viewDidLoad for AudioTableViewController
              {
                  [[self tableView] reloadData];
                  NSLog(@"viewDidLoad called for AudioTableViewController");
  
                  [super viewDidLoad];
  
                  self.title = @"Audio Files";//put this in application delegate
  
                  // Set up the buttons.
                  self.navigationItem.leftBarButtonItem = self.editButtonItem;
              }
  </code></pre>