问题
I am currently making a Facebook application for iOS that pulls the profile feed and puts it in a UITableView.
Right Now When the View Loads:
[facebook requestWithGraphPath:@"me/feed" andDelegate:self];
and in -(void)request:(FBRequest *)request didLoad:(id)result, i have:
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 is a global array, so i can access it in -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath.
so in -(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath, i have:
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;
So the question I am having a horrible time with is when a user posts a picture or video on the wall, how do i handle that? I would like to display the image/video in the tableview itself. Right Now, it just crashes. Any help would be greatly appreciated.
Thanks, Virindh Borra
回答1:
At what point is it crashing? Did you place any breakpoints in the code? When you add the UIImage to the imagesLocal array, are you the path at "https://graph.facebook.com/%@/picture" contains a valid image?
来源:https://stackoverflow.com/questions/10489494/facebook-ios-sdk