Tuesday, 6 August 2013

Unable to dismiss UIViewController from UITabBarController

Unable to dismiss UIViewController from UITabBarController

I have an iOS application which at the root has a UITabBarController
(which has three tabs).
In the first tab in viewDidAppear: I have the following to present
RegisterViewController if the user has not yet registered:
UIStoryboard *mainStoryboard = [UIStoryboard
storyboardWithName:@"MainStoryboard" bundle:nil];
RegisterViewController *registerViewController = [mainStoryboard
instantiateViewControllerWithIdentifier:@"RegisterView"];
[registerViewController
setModalTransitionStyle:UIModalTransitionStyleCrossDissolve];
[self presentViewController:registerViewController animated:NO
completion:nil];
When the user taps on a "Register" button in RegisterViewController it
presents QuestionnaireViewController once the HTTP response has been
received.
When the taps on a "Submit" button in QuestionnaireViewController I am
able to dismiss this with:
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:nil];
I then post a notification which RegisterViewController is listening for:
[[NSNotificationCenter defaultCenter]
postNotificationName:LoyaltyAppUserHasCompletedQuestionnaireNotification
object:nil];
Now, here is where my problem lies - When RegisterViewController hears the
notification I try and dismiss it, however cannot.
I have tried various connotations of dismissing it such as:
[[self tabBarController] dismissViewControllerAnimated:YES completion:nil];
which does nothing, and:
[[self presentingViewController] dismissViewControllerAnimated:YES
completion:nil];
which gives the following errors:
attempt to dismiss modal view controller whose view does not currently
appear. self = <RegisterViewController: 0x8525ea0> modalViewController =
<UINavigationController: 0x74545e0>
attempt to dismiss modal view controller whose view does not currently
appear. self = <UITabBarController: 0x8320060> modalViewController =
<RegisterViewController: 0x8525ea0>
Hopefully someone is going to be able to tell me I am doing something
stupidly wrong here.
Thanks, Nick

No comments:

Post a Comment