tags:

views:

25

answers:

0

I have a tabbed application which utilizes two main views. The first is to track the current run, and the second is a table of those which are saved. The default tab is the "current" tab. The problem is that if I try to add to the array in the second tab before I've literally 'seen' it, the table doesn't load correctly. I've managed to determine that the object has been added to the array, but it seems the table doesn't recognize it, and the array is reset once the table view is loaded.I'll post some code, maybe that will help.

RunHistoryViewController.m

    - (void)viewDidLoad {
 NSMutableArray *initArray= [[NSMutableArray alloc] initWithObjects: nil];

 NSLog(@"%i", [self.historyList count]);
 self.historyList=initArray;
 [initArray release];

 [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(updateHistoryList:) name:@"updateHistory" object:nil];
 [[NSNotificationCenter defaultCenter] addObserver: self selector:@selector(applicationWillTerminate:) name:UIApplicationWillTerminateNotification object:[UIApplication sharedApplication]];
 [super viewDidLoad];}

    -(void) updateHistoryList:(NSNotification *)notification {
 Track *newTrack= [[notification object] objectForKey:@"data"];
 NSLog(@"%i", [self.historyList count]);
 [self.historyList addObject:newTrack];
 [self.historyTable reloadData];
 NSLog(@"%i", [self.historyList count]);}

For instance, without tabbing over to the table view, I save a track. I get NSLog statements of '0' and '1' telling me that the object has been added to the array. But then when I tab over to the table view, I get an NSLog statement of '0' and an empty table. Does anyone know what's going wrong? Thanks.