harsh chauhan harsh chauhan - 5 months ago 35
Objective-C Question

show a Facebook user profile image from url to image view

I have a url of image which is fetched by the Facebook profile .I fetch those url and copy in to string "urlpicture" .In url picture my url show but when i pass in "geturl"which is a string type property in another file .when i go in to another file "geturl " is nil.

Thats why i can't show my image on image view.I save image url only in string format .Should i have some thing different to show my image on another view.

- (void) loginButton:(FBSDKLoginButton *)loginButton
didCompleteWithResult:(FBSDKLoginManagerLoginResult *)result
error:(NSError *)error
{
FBSDKGraphRequest *request = [[FBSDKGraphRequest alloc]
initWithGraphPath:@"/me"
parameters:@{ @"fields": @"id,name,picture,email,gender"}
HTTPMethod:@"GET"];
[request startWithCompletionHandler:^(FBSDKGraphRequestConnection *connection, id result, NSError *error) {
// Insert your code here
NSLog(@"%@",result);
if ([result isKindOfClass:[NSDictionary class]])
{ NSDictionary *pictureData = [result valueForKey:@"picture"];
NSDictionary *redata = [pictureData valueForKey:@"data"];
_urlpicture = [redata valueForKey:@"url"];

}





}];


HomeViewController *pushWithSlot=[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

[self.navigationController setViewControllers:@[pushWithSlot] animated:YES];
pushWithSlot.geturl=_urlpicture;

Answer

try this, actually pass the variable before navigation

HomeViewController *pushWithSlot=[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

 pushWithSlot.geturl=_urlpicture;
[self.navigationController setViewControllers:@[pushWithSlot] animated:YES];

the above one is not work, try this the reason is the URl is inside in your block

{    NSDictionary *pictureData  = [result valueForKey:@"picture"];
                    NSDictionary *redata = [pictureData valueForKey:@"data"];
                            _urlpicture = [redata valueForKey:@"url"];

       // call after URL Fetch
                 HomeViewController *pushWithSlot=[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

 pushWithSlot.geturl=_urlpicture;
[self.navigationController setViewControllers:@[pushWithSlot] animated:YES];
                }

then try this

  {    NSDictionary *pictureData  = [result valueForKey:@"picture"];
                    NSDictionary *redata = [pictureData valueForKey:@"data"];
                            _urlpicture = [redata valueForKey:@"url"];

       // call after URL Fetch
                 HomeViewController *pushWithSlot=[self.storyboard instantiateViewControllerWithIdentifier:@"HomeViewController"];

 pushWithSlot.geturl=pushWithSlot;
[self presentViewController:pushWithSlot 
               animated:YES 
             completion:nil];
                }
Comments