views:

66

answers:

1

I am having a problem that I cant seem to get to the bottom of.

In my view did load code, I am creating an array and attempting to populate the table. For some reason it only populates the data on EVERY OTHER time the app is run.

I put logs in viewDidLoad which runs as does viewWillAppear and outputs the correct count for the array.

Also, the UITableView specicic methods get called when it works and they just don't get called when it doesnt work. I cant figure out the root of this problem.

Again this occurrence happens exactly 50% of the time. Theres no dynamic data that could be tripping up or anything.

#import "InfoViewController.h"

@implementation InfoViewController

- (void)viewDidLoad
{
    NSLog(@"Info View Loaded"); // This runs

    infoList = [[NSMutableArray alloc] init];
    //Set The Data //Theres 8 similar lines
    [infoList addObject :[[NSMutableDictionary alloc] initWithObjectsAndKeys: @"Scrubbed", @"name", @"scrubbed", @"url", nil]];

    NSLog(@"%d", [infoList count]); // This shows the count correctly every time

    [super viewDidLoad];
}

-(void) viewWillAppear:(BOOL)animated
{
    NSLog(@"Info Will Appear"); // This Runs
}

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
  // This WILL NOT RUN when it doesnt work, and DOES show the count when it does run
    NSLog(@"Counted in numberOfRowsInSection %d", [infoList count]);
    return [infoList count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"ROW");
    static NSString *CellIdentifier = @"infoCell";  

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease];
    }

    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;   
    cell.textLabel.text = [[infoList objectAtIndex:indexPath.row] objectForKey:@"name"];

    return cell;
}


@end
A: 

You need a call to the tableView's reloadData method at the end of viewDidLoad.

progrmr
I've tried that all the results are the same. It's exactly 50/50.
Joshmattvander
Well, you do need that code in somewhere anyway. The problem sounds like a build error, maybe one of the build files is overwriting one of the other build files. Might you have two classes with the same name or something like that? Try removing the build folder, or do a build clean and see if that helps.
progrmr