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.