几周前我开始使用 IOS 和 Graph Api。我在用从 facebook 检索的专辑数据填充 UITableView 时遇到问题。我也将我的 appdelegete 设置为我的 uitabledatasource 和 uitabledelegate 在用户登录后发出以下请求:
NSString* fql = [NSString stringWithString:@"select object_id, cover_object_id, name, description from album where can_upload=1 and owner=me ()"];
NSMutableDictionary* params = [NSMutableDictionary dictionaryWithObject:fql forKey:@"query"];
[facebook requestWithMethodName:@"fql.query" andParams:params andHttpMethod:@"GET" andDelegate:self];
[theTable reloadData];
我在表格中实现了以下内容:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [self.resultData count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *SimpleTableIdentifier = @"SimpleTableIdentifier";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier: SimpleTableIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:SimpleTableIdentifier] autorelease];
}
NSUInteger row = [indexPath row]; cell.textLabel.text = [[self.resultData objectAtIndex:row] valueForKey:@"name"];
NSLog(@"the name %@", [[self.resultData objectAtIndex:row] valueForKey:@"name"]);
return cell;
}
并像这样管理结果:
- (void)request:(FBRequest *)request didLoad:(id)result {
if ([result isKindOfClass:[NSArray class]]) {
resultData=result;
[theTable reloadData];
}
NSLog(@"Result of API call: %@", result);
}
我得到了正确的查询结果,但表从未重新加载数据,因此它始终为空
最佳答案
首先,您需要在request:didLoad:
中保留resultData
(使用setter方法!)。
其次,您应该检查表是否根本不尝试重新加载数据,或者 TableView 数据源方法中是否出现问题。如果是前者,则 request:didLoad:
中的 theTable
实际上可能是 nil
,因此 reloadData
调用没有影响。使用调试器进行检查。
如果情况并非如此,我们需要更多信息。使用调试器检查代码,检查每个 TableView 数据源方法是否被调用以及该流程中的处理出错的位置。
关于ios - 用 Facebook 相册填充 UITableView |操作系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8250115/