How do I get my tableview's cells to display the data I want it to?
This is what I've done:
1.) Create a UIViewController subclass
2.) Have the subclass conform to the UITableViewDelegate and UITableViewDataSource protocols.
3.) Add a IBOutlet that is a UITableView
4.) Created a view XIB. In this I have made the file owner's the subclass class. Then I added a UITableView.
5.) Make the connection so that UITableView's delegate and dataSource is the File's Owner (ie, the UIViewController subclass).
6.) Then in code, I have this:
Code:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
if(displayLocalScores)
{
AppDelegate* appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
return [appDel.highScores count];
}
return 0;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *MyIdentifier = @"High Score";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:MyIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:MyIdentifier] autorelease];
}
// Configure the cell
AppDelegate* appDel = (AppDelegate*)[[UIApplication sharedApplication] delegate];
HighScore* cellData = [appDel.highScores objectAtIndex:indexPath.row];
NSLog(@"Setting cell stuff");
cell.text = [NSString stringWithFormat:@"%@: @i", cellData.username, cellData.score];
return cell;
}
- (void)viewWillAppear:(BOOL)animated
{
[highScoreTableView reloadData];
[super viewWillAppear:animated];
}
I can't understand why the cells don't display the string I give it :/