0

This might looks like another questions about passing data that have been already replied, but not (I have searched many times in stackoverflow)

I explain :

I use Firebase to authentificate users. In my problem, I use Google Sign In, and the func is located in Appdelegate

func sign(_ signIn: GIDSignIn!, didSignInFor user: GIDGoogleUser!, withError error: Error!) {

I have a navigation based on scrollView (https://github.com/jakespracher/Snapchat-Swipe-View) so the viewdidload/didappear is launched only once on my app (at the beginning, and not when I swipe to the UIController).

So my question:

I want to pass an image from my func sign (the Google Profile Image) from my Appdelegate, to a ProfileViewController. I want to do it from my func in my Appdelegate (the segue/present doesn't work. present because it's on appdelegate and segue because the viewdidload/did appear only launch once)

So how can I do ?

I tried this on my func sign on Appdelegate, but it goes nowhere with a nil on controller.profile.image :

let image: UIImage = UIImage(data: data)!
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("Profile") as! ProfileViewController

controller.profile.image = image

So please please please, I will be grateful if somebody helps me.

Thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Bonilla
  • 99
  • 2
  • 11

1 Answers1

0

you are going in wrong way, you are trying to set image to an ImageView of a ViewController which is not Loaded yet.

you can take and UIImage object in you view controller and On ViewDidLoad you can set the image to your ImageView.

class ProfileViewController : UIViewController {
var imageFromPreviousPage : UIImage?

@IBOutlet weak var profile: UIImageView!

override func viewDidLoad() {
    super.viewDidLoad()
    profile.image = imageFromPreviousPage
}
}

Now set your image to this image object

let image: UIImage = UIImage(data: data)!
var storyboard = UIStoryboard(name: "Main", bundle: nil)
var controller = storyboard.instantiateViewControllerWithIdentifier("Profile") as! ProfileViewController
controller. imageFromPreviousPage = image

Now you can push your navigation controller to above ViewController.

If you are trying it from Appdelegate didFinishLauch you need to set it as the root view of your window .

Hope it will help you.

Shubham bairagi
  • 943
  • 7
  • 25