Reputation: 468
I need to view the facebook newsfeeds in my UITableView. I send an asynchronous request to the server and I have obtained the list of newsfeeds. The problem is that i do not obtain, for each feed, the size of the image, and so I must send another asynchronous request to the server nested to previous asynchronous request. This code is very low efficent because I must reload my UITableView repeatedly (see my code).
I need get the image size so as set the height of the UITableCell and the dimension of UIImageView inside the cell.
Any idea to solve my problem ?
Below my code:
-(void)loadData{
//self.tableView.rowHeight = UITableViewAutomaticDimension;
screenRect = [[UIScreen mainScreen] bounds];
screenWidth = screenRect.size.width;
screenHeight = screenRect.size.height;
self.imgDic=[[NSMutableDictionary alloc]init];
self.desArr=[[NSMutableArray alloc]init];
self.mexArr=[[NSMutableArray alloc]init];
self.udidArr=[[NSMutableArray alloc]init];
[FBRequestConnection startWithGraphPath:@"/guide/feed" completionHandler:^(FBRequestConnection *connection,id result,NSError *error){
NSDictionary *data = [result objectForKey:@"data"];
for(NSDictionary *dic in data) {
if([dic objectForKey:@"description"]==nil){
[self.desArr addObject:@""];
}else{
[self.desArr addObject:[dic objectForKey:@"description"]];
}
if([dic objectForKey:@"object_id"]==nil){
[self.udidArr addObject:@""];
}else{
[self.udidArr addObject:[dic objectForKey:@"object_id"]];
[FBRequestConnection startWithGraphPath:[NSString stringWithFormat:@"/%@",[dic objectForKey:@"object_id"]] completionHandler:^(FBRequestConnection *connection,id result,NSError *error) {
[self.imgDic setObject:[result objectForKey:@"images"] forKey:[result objectForKey:@"id"]];
//NSLog(@"%@",[result objectForKey:@"id"]);
//NSLog(@"%@",[result objectForKey:@"images"]);
[self.tableView reloadData];
}];
}
if([dic objectForKey:@"message"]==nil){
[self.mexArr addObject:@""];
}else{
[self.mexArr addObject:[dic objectForKey:@"message"]];
}
}
[self.tableView reloadData];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
[self loadData];
}
Upvotes: 0
Views: 249
Reputation: 9912
There is no direct way using /me/feed, however you could use a Batch Request to get all the data at once.
Something like this, sent to https://graph.facebook.com/v2.3/ in the batch
parameter should return the size of the images.
[
{
"method": "GET",
"name": "get-feed",
"relative_url": "me/feed"
},
{
"method": "GET",
"relative_url": "?ids={result=get-feed:$.data.*.object_id}"
}
]
Upvotes: 1