Dismissing and presenting modalviewcontrollers - iphone

Goodday,
I got an application where an user logs in, and when the log in details is correct, the modalviewcontroller is dismissed. After the viewcontroller is dismissed, another view controller is called upon. This all goes fine except for the fact, when i want to switch back to my original controller: My login controller. I got the following code:
This code is called when the user logs in:
[self dismissModalViewControllerAnimated:YES];
Form *formcontroller1 = [[Form1 alloc] init];
[self presentModalViewViewController:formcontroller1 animated:YES];
After the user logged in, there is a logout button wich calls the following code:
[self dismissModalViewControllerAnimated:YES];
Postform3ViewController *logincontroller = [[Postform3ViewController alloc] init];
[self presentModalViewViewController:logincontroller animated:YES];
After the button is clicked, i get the following error message:
Postform3[5848:207] * Terminating app due to uncaught exception
'NSInternalInconsistencyException', reason: 'Attempting to begin a
modal transition from to while a transition is already in progress. Wait for
viewDidAppear/viewDidDisappear to know the current transition has
completed'
And i wonder if anyone can help me with this problem..

Actually, the error message tells you exactly what you need to do. You're dismissing a modal view controller, but not waiting until it's been dismissed before trying to present another. You should present the second view controller later, after -viewDidDisappear: has been invoked by the view controller machinery.

Related

Creating a logout button on iPhone app?

I have an app using storyboard. The layout is: Nav Controller > Login View Controller > Tab Bar Controller and each tab has a Nav Controller pointing to the UIViewController for that tab. I'm trying to create a log out button that would remove the TabBarController and go back to the Login View Controller. My code is as per below:
// In log out function
[self.tabBarController dismissViewControllerAnimated:YES completion:nil];
[self performSelector:#selector(patchSelector) withObject:nil afterDelay:0.3];
-(void)patchSelector{
[self.tabBarController.navigationController popToRootViewControllerAnimated:YES];
}
I keep getting the following error:
*** Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'presentedViewController for controller is itself on dismiss for
I tried reading the following regarding this:
No visible interface for dismissModalViewControllerAnimated:completion
http://www.touchthatfruit.com/viewwillappear-and-viewdidappear-not-being-ca
UITabbarController dismiss modal UINavigationController
However, none of the above helped with the error i'm getting. Is there something i'm missing in this? The error seems to indicate that the current vc is among those getting cleaned up.
When I remove my very first UINavigationController (the one before login screen) and I change the first line above to this: [self dismissModalViewControllerAnimated:YES];, it works...but only if I make it a modal segue. Easiest solution. Not sure why my original issue was, but i was able to get around it this way atleast!

EXC_BAD_ACCESS when popViewController

I am pushing BViewController from A properly. B contains a webview that starts loading a page when viewDidLoad. I am getting a strange behavior when popping B to A,
If webview finishes its load and then I execute popViewController (IBAction when touchUpInside on a toolbar button), popped to A so everything works perfectly.
However, if I popViewController immediately before webview ends its load, app crashes due to exc_bad_access. why? view is already loaded!
I checked on both situations viewcontrollers that are on navigation stack. Both cases with same result, 2 same objects, no difference!
-(IBAction)goBackOrg:(id)sender{
NSArray *viewControllers = self.navigationController.viewControllers;
[[self navigationController] popViewControllerAnimated:NO];
}
and for previously pushing it, I am using
if(!self.BController){
self.BController = [[BViewController alloc] initWithNibName:#"BViewController" bundle:nil anUrlDest:urlSocial];
}
[[self navigationController] pushViewController:self.BController animated:NO];
EXC_BAD_ACCESS occurs when you're trying to access an object that has been deallocated.
So the following could be your problem: when you pop ViewController B, it is being unloaded. If the web view loading finishes after ViewController B is unloaded, some piece of callback code is getting executed that is trying to do something with your ViewController or its view (or similar).
May be You are loading your webView on Thread and when you are using thread then you cannot do changes in UI otherwise your app will crash.
So just do this task on mainThread .

crashing on ios device while navigation using UIModalTransitionStylePartialCurl in xcode 4

i am using UIModalTransitionStylePartialCurl on the ios 4 device,in my test app i have 2 classes where a single button in each class, in first page onclick of the button it ill navigate to 2nd page (by curling the page up) but in the 2nd page when i click backbutton its crashing but not navigating back to my first page
following is my code used for navigation
ViewController *MainWin = [[QIAViewController alloc] initWithNibName:NULL bundle:NULL];
MainWin.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:MainWin animated:YES];
[MainWin release];
this is the crash log:
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Application tried to present a nested modal view controller while curled <QIAAdminPassCnf: 0x583e040>.'
*** Call stack at first throw:
If you read the documentation for UIModalTransitionStylePartialCurl, you will see that once you've used it you can't present any more modal views.
If you want to navigate back, I think you should do,
[self dismissModalViewControllerAnimated:YES];
rather than creating a new view controller instance.
You may well have added the Action twice in Interface Builder. Go to the ViewController and to the Triggered Segues on the right and "x" do delete the extra one. LOL

iphone - Modal view controller disappears?

So let's say I have a viewController named homeViewController, and another view controller named listViewController
I display listViewController on top of homeViewController as a modal.
If the user clicks the off button, and then comes back to the app the modalViewController is gone.
ListViewController *listViewController = [[ListViewController alloc] init];
[self presentModalViewController:listViewController animated:NO];
[listViewController release];
Note: Application doesn't startup from scratch when this occures and the previous state is still visible
I'm assuming that by "off button" you mean the user locks the iDevice.
I just tried this in one of my apps and the modal view controller is still there after unlocking. My guess would be that it's something unrelated to the code you have posted. I would check your - (void)applicationWillResignActive:(UIApplication *)application method in your app delegate class and see if there's anything there that would dismiss the modal view controller.
Here is what the problem was.
When the user locks the screen I remove homeViewController from window
[homeViewController removeFromSuperview];
When user starts the app again I do
[windows addSubview:homeViewController];
that brings homeViewController on top of its modeal

iOS How to hide a prior subview

I have a situation where I am performing some initialization in an App. Upon first startup I have to present an EULA with an I Agree/I Don't Agree button selection. When the I Agree selection is made I display a modal view which prompts for a username and password. This all works fine. The problem is that after the username and password are verified and the modal view is dismissed. I am left with the EULA view still being displayed on the screen rather than the base table view of the App. I do the following in the EULA viewcontroller code:
- (IBAction)didAgree:(id)sender {
LoginViewController *lvc=[[[LoginViewController alloc] init] autorelease];
lvc.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:lvc animated:YES];
[self.view removeFromSuperview];
}
If I move the last line (removeFromSuperview) to before the presentModal call then, of course, the Login view does not display.
In the login view controller code I have this after the login button is pressed:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
[[self parentViewController].view removeFromSuperview];
If I run with this code, the modal view disappears and the table view appears briefly before disappearing with the EULA view remaining on the screen. If I comment out the second statement, then I never see the table view.
I know this I am missing something incredibly obvious but I am at a loss and have been stuck on this for quite a while.
I think the problem is here:
[self presentModalViewController:lvc animated:YES];
Mainly the self there. This means that you present the login screen modally from what self is: your EULA-ViewController. You can't remove the EULA screen now.
I suggest presenting the login screen first, maybe either all grayed out or not showing anything at all, and the presenting the EULA modally from it.