UINavigationController skipping a pop - iphone

I have 3 view controllers, one is the root, which pushes the next, which pushes the next. Each time you can go back (pop), using the normal back button that appears by default.
However when the 3rd view is visible, when the user taps the back button I need it to skip out the the 2nd view controller, and go (pop) directly to the root view controller.
How can I override the default back button behaviour? (I'd like to keep the shape of the back button, and not replace it with a square bar button)

You could try to have an object implement UINavigationControllerDelegate and enforce this behavior. You could also have a designer create the same size and shape asset and you could use this as the background for a button.
However, I'd rethink your UI if you really need to do this. It is contrary to the user's expectations of how a navigation controller should work.

Related

How can I load into a different view in a popover?

I have some code that opens a popover window that displays some text. This is done by an action segue rather than actual code in a storyboard. Is there any way, that I can load into a different view by pressing a button on the popover view and have it load into the next view? I've tried using another action segue, but it puts a popover into my current popover over the button that I press. Thanks!
This kind of thing can't be done with just storyboards; some code will be necessary.
Here's how I would do this: instead of trying to use two separate popovers, use one popover with kind of a "nested" setup. The popover's content view controller would contain, say, a Page1ViewController and a Page2ViewController. When first displayed, the main controller would install page 1's view. You could maybe wire the action from page 1's button directly to the main controller, but I recommend that you use delegation for this. Create a protocol that's something like Page1ViewControllerDelegate and adopt the protocol in your main controller, then in the delegate method for page1ControllerRequestTransition(_:) or whatever you choose, just grab the page 1 view out and swap the page 2 view in. You can even have the two views be different sizes; the popover will automatically adjust itself.
Oh, and don't forget to disable translatesAutoresizingMaskIntoConstraints and add appropriate constraints to fix the four sides of each page's view.

Xcode - Manually load a view controller

What I am asking may be impossible and sound weird, but here it goes.
Here is similar to what I want to achieve:
A user opens the app for the first time, there are two tab bars, in the first one (he has not tapped the second one yet) he presses a button that should initiate a progress view and text view changes and other view changes EVEN THOUGH the user has not loaded the other view controller by clicking the second tab bar.
So, is there a way to generally load a view controller before the user manually loads it himself, I know calling viewDidLoad manually will not help, any suggestions? Pretty confusing, it is like modifying a view but the controller has not loaded yet...
Thanks!
Make the changes in the other view controller and then let the controller configure its own view when it does its natural loading.

Tab bar at top and bottom

I would like to develop a ipad apps which has a menu at the top of the screen as well as at the bottom.
There are four buttons on the top of the screen, and there are 10+ buttons at the bottom tab bar, which can be scrolled horizontally.
How can I write the root view controller as a framework for this operation?
Should I customize the UIViewController class or UITabBarViewController?
Thanks
EDIT:
Sorry for being unclear. Let me restate my question.
Actually my app will have the following hierarchy.
'Front Page' is simply a page (view controller) for user to choose language. After choosing the language, 'Menu Page' view controller is displayed.
Starting from Menu page and ALL view controllers (VC) in below, the page layout is something like this.
As you can see, there are top menu and bottom menu. Clicking on the buttons the app will quickly jump to the corresponding view controller (3rd level in the tree, VC1,VC2,VC3 etc) . And for every view, there is a BACK button on every page, clicking which will back to the parent view controller.
I was thinking to implement this by using a tab bar view controller and a navigation view controller but I still do not have a clear idea how to implement this.
Or maybe should I just use the navigation view controller and hide the top tool bar except the back button, and display an overlay UIView as menu which is on top of all other UIViews.
Can somebody help me? Thanks.
Since this is the outermost container for my app I hope to do it properly at start..
Sorry for my long question.
If you really want to develop a framework for this logic .You need to create Manager, ViewController, View, DAO ,Model and other classes according to your needs.
I assume you want to add the buttons dynamically to the tabbar (and if it scrollable , it must be a scrollview).You can use Toolbar for upper view but then it won't be in sync with the bottom-view(visually).In that case you will have to create your own customized views to look like a tabbar.
The manager will basically keep a track of all the buttons and different states of events and action on the views and the same information can be accessed via a static method form the viewcontroller.
Well you have not detailed on your needs , so it's difficult to predict the entire architecture.
You need a container view controller to manage selection of VC's 1-4.
clicking which will back to the parent view controller
Parent view controller is used to mean the container vc in a container view controller scheme - I'm not sure that's what you mean in this comment. Where exactly does the back button go?
See this link for more info about container VC's.
https://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/CreatingCustomContainerViewControllers/CreatingCustomContainerViewControllers.html
You should be able to embed a tab bar controller in the content view of the container VC. Should be able to but it might be really buggy if there is a lot of communication between the child vc's.
The hard part is the back button. Basically it must be a button that goes back to VC 1-4 depending on which section you are in. The easiest way to do it is to make sure that when you cycle view controllers, pass the back button information as to which VC is the current child so it knows which VC to navigate to when you press it.

Button not always getting the touch. Touch sometimes goes to another View Controller

I'm looking for some kind of solution to a problem I have.
I have a main view controller. On this view controller I have a button it works well most of the time. But when i pop up smaller view controller onto my main view controller, a part of the small view controller is behind the button.
So the button is is still on the front of the sceen, with the small view controller behind it.
The small view controller seems to take the key presses that were ment for the button. Is there a way to get the button to take the keypresses? I though it having the higher z order would make this so, but obviously not. Is there a work around of this?
Or am I going to need to have an invisible button on my small view controller that calls back to the parent view controller to say the button was pressed.
Many Thanks
C :)
Key presses go to the first responder of a window not the frontmost view in the z order. So after popping up the small view controller make the button first responder then key presses will go to it.

Where should I "save" changes in my iPhone view to 'create new' of an object?

I have a view that creates a new core data managed object, and fills in all the required properties and also allows optional ones. I originally had a "Done" button on the top left, and when that was pressed, I validated the object then saved and removed the view.
Now I have an edit/done type setup on the top right, so sometimes there are two identical "Done" buttons on the top of the view. I want to switch the left side button so that it just has the normal "Back" button, then somehow validate and stop the view from being removed if it doesn't validate. I can't find any way to capture the method called by that back button and modify it, and viewWillDisappear doesn't work cause there's no way to abort the disappearing.
How can I make this work? I need to validate this, then save, then remove the view if validate and save worked only.
It sounds like your view is a perfect candidate to be pushed modally instead of through the navigation controller stack.
Push the view that creates your NSManagedObject modally:
[self presentModalViewController:yourViewController animated:YES]
Then continue to use your top right EDIT/DONE button for editing/validation as you currently are and when validation is successful simply save your object and dismiss the modal view controller from the parent view controller:
[[self parentViewController] dismissModalViewControllerAnimated:YES];
For more details check http://developer.apple.com/library/ios/featuredarticles/ViewControllerPGforiPhoneOS/ModalViewControllers/ModalViewControllers.html#//apple_ref/doc/uid/TP40007457-CH111-SW14
If you still want to use a button on the left hand side perhaps you can change the right button to say EDIT/CANCEL and add a DONE button on the left side that is only visible when you're not in EDIT mode. If appropriate you can point the DONE button to run through the same validation process before dismissing the modal view using the code above but it probably makes sense that the EDIT/CANCEL button takes care of it.
I hope this helps.
Rog
There is no documented way to intercept the standard back button of UINavigationController. If you want this functionality, your only option would be to customize leftBarButtonItem with a custom button.
When the user taps that button, you can first validate your object and then call popViewControllerAnimated:.
It's hard to mimic the look of the built-in back button, though.