Disabling the modal view manager from the application delegate

I use facebook sdk to enter my application. If the user is not logged in, a logon modem appears. After a user logs in, he notifies the application delegate if the logon was successful. If that were the case, I want to reject the VC modal login. How to do this from an application delegate?

+4
source share
2 answers

The appDelegate application needs some sort of way to find out who the viewController is hosting, so it can send a dismissal message. You need to figure out how to do this. One way is to define ivar on appDelegate "callDismissOnMeIfFaceBookFails" and set it when you are in this situation, otherwise its nil.

Please note that if its nil, appDelegate can send a letter of resignation without any overhead, no problem! Use nil messaging to your advantage (I use it all the time). [Beyond this: I see so much code "if (obj) [obj message];" Do not make if messages - just send a message - if obj is zero, it has no effect and is processed efficiently!]

EDIT:

So you have the AppDelegate class. In #interface, define a property:

@property (nonatomic, strong) UIViewController *callDismissOnMeIfFaceBookFails; 

and in implementation you are @synthesize. Define a method:

 - (void)dismissLoginView { [callDismissOnMeIfFaceBookFails dismissModalViewControllerAnimated:YES]; callDismissOnMeIfFaceBookFails = nil; // don't need it now, this unretains it } 

So, before presenting a modal view controller, the representing object sets the appDelegate property "callDismissOnMeIfFaceBookFails" for itself.

When the user has successfully logged in, the login object sends an appDelegate message, which notifies the rejectLoginView function.

+4
source

You can try to reject the presented ViewController, as something must present the modal view controller

 UINavigationController *navigationController = (id) self.window.rootViewController; [[navigationController presentedViewController] dismissModalViewControllerAnimated:NO]; 

If you want to check whether any particular ViewController is presented (i.e. only to be removed when a specific one is displayed), you can add a check.

 UIViewController *viewController = [navigationController presentedViewController]; if ([viewController isMemberOfClass:[YourViewController class]]) { [viewController dismissModalViewControllerAnimated:NO]; } 
+7
source

All Articles