Я пытаюсь отобразить список друзей в UITableView.
Я загружаю друзей:
- (void)viewDidLoad
{
[super viewDidLoad];
[self apiGraphFriends];
}
Затем я устанавливаю свои результаты в:
- (void)request:(FBRequest *)request didLoad:(id)result
{
friends = [[NSMutableArray alloc] initWithCapacity:1];
NSArray *resultData = [result objectForKey:@"data"];
if ([resultData count] > 0) {
for (NSUInteger i=0; i<[resultData count]; i++) {
[friends addObject:[resultData objectAtIndex:i]];
}
} else {
//[self showMessage:@"You have no friends."];
}
}
и я реализую требуемый UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [friends count];
}
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath: (NSIndexPath *)indexPath
{
//NSManagedObjectModel *friend [fetch
FriendCell *cell = [tableView dequeueReusableCellWithIdentifier: @"friendCell"];
cell.cellName.text = [friends objectAtIndex:indexPath.row];
return cell;
}
Проблема в том, что метод cellForRowAtIndexPath вызывается до получения моих данных. Как предотвратить автоматическую инициализацию табличного представления и только инициализировать его, когда у вас есть данные для него?