Facebook iOS SDK - jumping to another view

I am new to iOS development and I have started implementing the Facebook SDK with ARC. As shown in the tutorials, I've added the Facebook instance in the AppDelegate. I need the application to login to Facebook not when the application didFinishLoading but when a button is pressed.

I've created a button and an IBAction in my view controller and I'm calling a function from the AppDelegate with the IBAction. The function from the AppDelegate does the login and then, when everything is OK, returns me to the same view. I need to implement the following:

  1. When I login the function fbDidLogin is being called and I want my application to go to another view. How do I do that from my AppDelegate?

  2. This function is in the AppDelegate, because the facebook instance is there. Is there a better sollution regarding the architecture of the applicaiton?

Thank you!

Upvotes: 1

Views: 494

Answers (2)

Aatish Molasi
Aatish Molasi

Reputation: 2186

As Mahmoud pointed above you could use

- (void)fbDidLogin {
        [self.navigationController pushViewController:<#(UIViewController *)#> animated:<#(BOOL)#>]
  }

but from my experience its better to keep your facebook object as a singleton (read Singleton) as if you need to access this object elsewhere in your program you would need to access your appdelegate object again which would make for really messy coding

Making it a singleton on the otherhand would give you more control over the object and you actually require only one instance of facebook object

Upvotes: 1

Mahmoud Adam
Mahmoud Adam

Reputation: 5852

try to add Facebook code in a viewcontroller and make the Facebook object as property on it. in the Appdelegate add this view controller to your window and when getting the authentication back from facebook access the facebook object inside the view controller

[viewcontroller.facebook handleOpenURL:url];

and fbDidLogin will be inside your viewcontroller so you can push another view

- (void)fbDidLogin {
            [self.navigationController pushViewController:<#(UIViewController *)#> animated:<#(BOOL)#>]
}

Upvotes: 1

Related Questions