UITableView populating EVERY OTHER launch

Posted by Joshmattvander on Stack Overflow See other posts from Stack Overflow or by Joshmattvander
Published on 2010-05-06T20:09:53Z Indexed on 2010/05/06 22:48 UTC
Read the original article Hit count: 158

Filed under:
|

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

© Stack Overflow or respective owner

Related posts about iphone

Related posts about uitableview