我想在UITableView中显示朋友列表。用动态数据初始化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',你如何prev如何自动初始化表视图,并且只有在有数据时才初始化它?
谢谢,就像一个魅力:) – Brett