2

I am working in an iOS app that let the user logged in using his Facebook account. we the user logged in i want to push the profile ViewController filled with the user data ; sorry for this long preliminary .

the problem is when i use instantiateViewControllerWithIdentifier method to initiate the profile view controller . its outlet component are all nil

here is the code where i face the problem

- (void)loginViewFetchedUserInfo:(FBLoginView *)loginView
                        user:(id<FBGraphUser>)user {    
profileViewController = [self.storyboard        instantiateViewControllerWithIdentifier:@"CGProfileViewController"];
profileViewController.fbProfilePictureView.profileID=user.objectID;
profileViewController.nameLabel.text=user.name;
profileViewController.locationLabel.text=user.location.location.city;

//    [self presentViewController:profileViewController animated:YES completion:nil]

}

enter image description here

is there any problem with my code ? what should i do ? Thanking in advance

Ahd Radwan
  • 1,090
  • 4
  • 14
  • 31
  • 1
    see this [answer](http://stackoverflow.com/questions/12523198/storyboard-instantiateviewcontrollerwithidentifier-not-setting-iboutlets) – Fabio Felici Mar 26 '15 at 14:12

1 Answers1

5

The problem here is that you are referencing outlets that haven't yet been created. I would try adding the User model as a property of the view controller (or use some sort of intermediate controller for this), setting the user property in your function above, then in viewDidAppear set the text of all the controls appropriately using the User model.

If you do this on the viewDidAppear function you can be certain all of your views have been instantiated. this is also better design, after all; why does your LoginViewController class need to know about the internals of profileViewController? Encapsulating logic in this way will lead to less problems down the line.

Hope this helps.

Alex Brown
  • 1,613
  • 1
  • 13
  • 23