我目前正在为 iOS 制作一个 Facebook 应用程序,它会提取个人资料提要并将其放入 UITableView。
现在当视图加载时:
[facebook requestWithGraphPath:@"me/feed" andDelegate:self];
在 -(void)request:(FBRequest *)request didLoad:(id)result 中,我有:
NSArray *messagesFBData = [result objectForKey:@"data"];
NSMutableArray *friendIds = [NSMutableArray arrayWithCapacity:messagesFBData.count];
NSMutableArray *fromData = [NSMutableArray arrayWithCapacity:messagesFBData.count];
NSMutableArray *imagesLocal = [NSMutableArray arrayWithCapacity:messagesFBData.count];
for (int x = 0; x < messagesFBData.count; x++) {
if ([(NSDictionary *)[messagesFBData objectAtIndex:x] objectForKey:@"message"] != nil) {
[friendIds addObject:[((NSDictionary*)[messagesFBData objectAtIndex:x]) objectForKey:@"message"]];
NSLog(@"loop Log: %@", [(NSDictionary *)[messagesFBData objectAtIndex:x] objectForKey:@"message"]);
[fromData addObject:[((NSDictionary*)[messagesFBData objectAtIndex:x]) objectForKey:@"from"]];
NSLog(@"%@", [((NSDictionary*)[messagesFBData objectAtIndex:x]) objectForKey:@"from"] );
NSDictionary *fromDataDictionary = [fromData objectAtIndex:x];
[imagesLocal addObject:[UIImage imageWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:[NSString stringWithFormat:@"https://graph.facebook.com/%@/picture", [fromDataDictionary objectForKey:@"id"]]]]]];
NSLog(@"facebook ID: %@", [fromDataDictionary objectForKey:@"id"]);
} else
{
NSLog(@"Nil Called");
}
}
// don't forget to call loadData for your tableView
messages = friendIds;
images = imagesLocal;
NSLog(@"Equalized");
self.facebookTableView.delegate = self;
NSLog(@"Delegate Set");
[facebookTableView reloadData];
images 是一个全局数组,所以我可以在 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 中访问它。
所以在 -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath,我有:
NSLog(@"Cell For Row Called");
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:@"messageCell"];
NSString *story = [messages objectAtIndex:indexPath.row];
cell.textLabel.text = story;
UIImage *image = [images objectAtIndex:indexPath.row];
cell.imageView.image = image;
cell.alpha = 1;
return cell;
所以我遇到的问题是当用户在墙上发布图片或视频时,我该如何处理?我想在 tableview 本身中显示图像/视频。现在,它只是崩溃了。任何帮助将不胜感激。
谢谢,维林德博拉