views:

334

answers:

1

I created a UITableView programmatically (not using a XIB). It reads a *.plist file containing an NSMutableArray of NSDictionary objects. The problem I am experiencing is this: When I display the objects in the UITableView, it never shows the object at row zero. I know this because I get the following NSLog output:

2009-06-01 10:02:34.566 Color[784:20b] array count = 4
2009-06-01 10:02:34.570 Color[784:20b] row = 3: Air
2009-06-01 10:02:34.570 Color[784:20b] row = 2: Earth
2009-06-01 10:02:34.571 Color[784:20b] row = 1: Water
2009-06-01 10:02:34.571 Color[784:20b] row = 0: Fire

What I will see, in this case, is a table with Water, Earth, and Air (but no Fire). If I add another object, then Fire will appear but the new object will not. Therefore, it is always the object at row 0.

Here is some relevant code:

@interface LoadViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {
    NSMutableArray *loadedObjects;
}

- (void)viewWillAppear:(BOOL)animated {
    self.loadedObjects = [self getCurrentData];
    NSLog(@"array count = %d", [self.loadedObjects count]); 
    [self.tableView reloadData];
    [super viewWillAppear:animated];
}

-(NSInteger)tableView:(UITableView*)tableView numberOfRowsInSection:(NSInteger)section {
    return [self.loadedColors count];
}

-(UITableViewCell*)tableView:(UITableView*)tableView cellForRowAtIndexPath:(NSIndexPath*)indexPath {
    static NSString *Identifier = @"Identifier";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:Identifier];
    if(cell == nil) {
     cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:Identifier] autorelease];
     cell.showsReorderControl = YES;
    }
    NSUInteger row = [indexPath row];
    NSDictionary *obj = [self.loadedObjects objectAtIndex:row];
    cell.text = [obj objectForKey:@"Name"];
    NSLog(@"row = %d: %@", row, [obj objectForKey:@"Name"]);
    return cell;
}

In the code snippets you can also see my output to NSLog.

When I had populated UITableViews from a NIB I had never experienced this problem. Any suggestions are appreciated.

Thank you in advance.

A: 

I feel kind of dumb, but maybe this could be useful to someone else...

What I failed to mention in my description (because I didn't think it was relevant) was the fact that I also instantiated a UINavigationBar to have an Edit button in the upper-right corner. In a nutshell, the nav bar was obscuring the first record in the table.

The reason why I couldn't see this is because I did this:

[self.tableView addSubview:navBar];

and what that did was to "stick" the navBar to the table, so scrolling could not reveal the missing row. When I changed that line to:

[self.appDelegate.window addSubview:navBar];

I could drag the first record out from under the navBar because they then become sibling views.

I apologize for the misplaced question.

Hunter D
Why are you adding a navigation bar manually instead of using the UINavigationController which adds a nav bar to conained view controllers automatically?
Kendall Helmstetter Gelner