Creating a logout button on iPhone app? - iphone

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!

Related

Modal segue not working from code

I've already spent the whole day in an issue and did not find a solution yet. I have a UITabBarViewController and I am trying to fire off a modal segue from one of its tabs. I've already created the view I want to segue to, created the segue itself (from the tab's view controller to the target's view controller) and the identifier. In order to test my segue I created a UIButton in my tab and wrote the following code on its action:
[self performSegueWithIdentifier:#"showProductInfo" sender:self];
The modal segue worked fine. But if I try to write the same code to be performed somewhere else (inside a specific method that is called after I receive a web service response) the segue simply does not work. I get the following error:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'Receiver () has no segue with identifier 'showProductInfo''
This is driving me crazy! Any help is more then welcome.
Editting:
Some additional findings:
If I take off the performSegue from the method I am currently using (which by the way is called by DidFinishLoading) and put it on ViewDidLoad the segue is performed successfully.
Thinking that it could be a thread related issue I included the performSegue inside a dispatch_async(dispatch_get_main_queue()... But the error is the same !
If your destination viewcontroller is inside a navigationcontroller, then take a look at this question:
http://stackoverflow.com/questions/8041237/how-to-set-the-delegate-with-a-storyboard
Furthermore, from the error it looks like the segue you are trying to perform is not attached
to the viewcontroller you are starting from. So,Try to remove the seque and drag it from the
viewcontroller.
The current view controller must have been loaded from a storyboard. If its storyboard property is nil, perhaps because you allocated and initialized the view controller yourself, this method throws an exception.
Make sure you have Storyboard ID for your destination VC (in this example myViewController).
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"myStoryboard" bundle:[NSBundle mainBundle]];
UIViewController *myViewController = [storyboard instantiateViewControllerWithIdentifier:#"MyController"];
[self.navigationController pushViewController:myViewController animated:YES];

Getting warning message while Pushing a View

In my application I want to push a different view from the ViewWillAppear of my current view.
Application is running but I am getting a message in console is that
Finishing up a navigation transition in an unexpected state. Navigation Bar subview tree might get corrupted.
Can you help me.
In absence of some requested code I'll take a guess that you push your new viewController with the animated flag to YES. In that case set your previous ViewControllers transition to nonanimated. In other words(code):
[self.navigationController pushViewController:firstViewController animated:NO];
in its (firstViewController) ViewWillAppear:
[self.navigationController pushViewController:secandViewController animated:YES];

Dismissing and presenting modalviewcontrollers

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.

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 ModalViewController For Table View Open by Button?

App Description: I have a UIWebview and a Toolbar beneath it. A button on the toolbar should bring up a modal table view, but it does not.
The toolbar has four buttons:
Previous: Goes to previous site
Next: Goes to the next site (these two being different than the default goForward and goBack methods)
Menu: Display a modalViewController with a TableView of all the available sites (sites will be limited to an array of site links that the next and previous buttons cycle through)
Refresh: Refreshes current site
Application has four main classes/files
WebAppDelegate.h and .m
ListViewController.h and .m (which has the Table View in its xib and the code to fill the table in the .m/ be the modal view controller)
There is only one warning and no errors.
Warning: 'WebAppDelegate' may not repsond to '-presentModalViewController:animated:'
When I run the program, everything is fine until I click the Menu button. I receive this runtime error
[WebAppDelegate presentModalViewController:animated:]: unrecognized selector sent to instance
Below is the code for the Menu button, which is currently in WebAppDelegate.m
-(IBAction)menu:(id)sender {
ListViewController *aListView=[[ListViewController alloc] initWithNibName:#"ListViewController" bundle:[NSBundle mainBundle]];
[self setListController:aListView];
aListView.modalTransitionStyle=UIModalTransitionStyleCoverVertical;
[self presentModalViewController:aListView animated:YES];
[aListView release];
}
Any ideas on what causes the application to crash and why the modal table view does not display?
The error message tells you exactly what your problem is - you're sending a selector to an object that doesn't respond to that selector.
[self presentModalViewController:aListView animated:YES];
self in this case in your instance of WebAppDelegate, which is probably a subclass of NSObject, not UIViewController. presentModalViewController:animated: is a method on UIViewController, so you need to send that message to whatever view controller is currently displayed (or perhaps a navigation controller) if you want to present another view controller modally.
Do not ignore compiler warnings - the one warning you have is likely telling you that...
'WebAppDelegate' may not respond to '-presentModalViewController:animated:'
...which, again, is exactly your problem.
[self.navigationController presentModalViewController:aListView animated:YES];