I’m a novice programmer working through “The Complete Idiot’s Guide to iPad & iPhone App Development” by Troy Brant (my problem is in Chapter 14, the “Frenemy” app). At the time of publication Xcode 4.2 did not exist. This fact and the fact that the book is laden with typo’s has made this learning experience frustrating but valuable. Alas, I have come upon an issue I seem to be unable to solve. I have created a table view and populated it with twitter usernames. I have followed the book to the letter and even downloaded the author’s “finished” source code. At runtime, all that happens is my table view and navigation bar display but the table is completely empty. When I run his “finished” source code, the exact same thing happens. My question is: is there a specific method I should be calling (like updateInterface, for example) in order to display the data I’ve told the table to gather or should the…
-(void)viewDidLoad
{
[super viewDidLoad];
self.title = @"Frenemies";
frenemiesTableView.dataSource = self;
frenemiesTableView.delegate = self;
}
…method suffice? Also, if I should be calling an updateInterface relative, how do I define that method? I’ve been using this website all week and finally decided to sign up and ask my first question because you guys have been able to steer me to great answers so far. I greatly appreciate any advice.
the following is in my FrenemiesViewController.m Class:
-(NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
//following line tells the table to create as many rows as rootUser has frenemies
return [rootUser.frenemies count];
}
//give the table view the cell to display for a single row
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
//REUSE CELLS FOR BEST SCROLLING PERFORMANCE
static NSString *cellId = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (!cell)
{
//create a cell only if one couldn't be reused
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellId];
}
//DISPLAY FRENEMY'S NAME INSIDE THE CELL
NSDictionary *frenemyDict = [rootUser.frenemies objectAtIndex:indexPath.row];
cell.textLabel.text = [frenemyDict objectForKey:@"name"];
return cell;
}
You are not showing us your dataSource. Your table needs some kind of data to load.
Return the number of objects in
someArray.Load
someArrayinto the table: