Dismissing view controllers with no fixed order - ios

I'd like to know the best way to handle view controllers when there are multiple ways for the user to navigate through an app. The problem is that the user might (for example) trigger a segue by selecting a table row, Then, from the presented view controller they might click a button in a custom toolbar to go somewhere else.
I'm pretty new at this, so while I understand using a segue to present a view controller, and then having to dismiss the presented view controller at some point, I'm less clear on how to manage things when a user has free reign to go wherever they want! I'm using container views to embed a header and a custom toolbar at the bottom of each view. Should I be using a container for each view controller as well?

If you are quite down the stack and you don‘t want to offer a back button for simplicity, then you go up the stack by calling dismiss and tell the delegate where you want to go until you reach the appropriate level which can move you up until you are where you wanted to go.
The alternative is to move up the delegate chain until you can move down again and from there call dismiss and then go down where you want to go.

Related

For swift iOS app dev, how do I segue to a view that takes up part of the screen only?

GroupMe is a good example. I want to implement something similar to this..
when you press the top left icon it'll bring you to the view on the left hand side, and when you click the right hand side of that view (the chats) it will bring you back
As the documentation says:
Use segues to define the flow of your app’s interface. A segue defines
a transition between two view controllers in your app’s storyboard
file. The starting point of a segue is the button, table row, or
gesture recognizer that initiates the segue. The end point of a segue
is the view controller you want to display. A segue always presents a
new view controller, but you can also use an unwind segue to dismiss a
view controller.
As said by Apple© segues are for changing View Controllers only and cannot be used to move single views. I suggest using animations to achieve the effect you are searching, however segues are definitely not what you are looking for. Maybe this question on stackoverflow.com may help you.
And please be sure to check for information by yourself first, I got this information in less than 5 minutes by searching on Google.com.
Regards -Jorge

I need some clarity on Navigation Controllers

I have a total of 3 views. A menu, the main view where the action happens, and a settings menu.
You can access the settings from both the menu and the main view and go back using the back button provided by the Navigation Controller.
In the main view I have hidden the NavigationBar to free some space, and there's a specific button to go back to the menu. From what I know and have read, I assume this just adds more and more views to the Navigation Stack if I keep going from the main view to the menu again and again, creating a lot of views in the stack.
I'd like someone to tell me whether my assumption is true or not, and evt. explain me the whole process behind navigating and views.
UINavigationController has a property viewControllers which is the stack of view controllers that have been pushed there.
If you use push segues in your storyboard each time you trigger this segues you push the current controller to the stack.
If you have a special logic I suggest you manage controllers programmatically.
This might clear it all.
There are basically following types of Segues to navigate to any viewController
Show (Push)
Show Detail (Replace)
Present Modally
Present as Popover
And to move back use Unwind Segue
You can read more regarding this here

Segue to "self" - Transition back to initial controller

I would like to have three separate tableViews, show the middle view automatically (root view), and access the other two via a button or segmented control. That logic can come later. When I access the first I want it to slide in from the left, when I access the third I want it to slide in from the right to give it the appearance of the middle view controller always being there and only moving left and right via transitions.
Using storyboard segues is giving way to many complications - because my tableViewController is the initial root view, there is no way to segue to self from self when the button or segmented control is accessed. I feel like this must be a semi-standard implementation. Is there a best practice to implement this UI? Should I build my own custom container class and swap controllers and associated view in and out?
You should create 2 segues from you root to left and right table view. When you would like to go back, to root controller, use unwind segues.
What are Unwind segues for and how do you use them?

Split view MasterViewController with multiple table views

I have a split view working great. However, I'd like to be able to drill down on my Master-Detail view's UITableView. For example, I have a list of ages: 0, 1, 2, 3, 4, 5. When the user presses 3 I would like a new UITableView to be presented with all the kids names that are 3.
Ideally I'd like use Storyboards to accomplish this (link an add button to take me to the next UITableView). When I try and add a view it shows up as a full screen view. How can I make this view show up in the Master section of the split view?
When using Storyboards, if you want to have multiple UITableViews so it will allow the user to drill down categories, you must use the Push Segue (set it to Master). Make sure you are not pushing a UINavigationController, but just the view you want listed. Then, to get back just use [self.navigationcontroller popViewControllerAnimated:YES];.
EDIT: (more info as asked for)
So in XCode/IB when you are on your main view and right click and drag it to another view, you will be presented with different choices. You want to select Push instead of Modal. This will allow it to push a new view onto the stack. You can also set it's destination to Master and it will size the IB view correctly.
Also, you don't always have to use a button to connect a view. You can also drag from the view controller itself to another view controller instead of a button to view controller. Then in your button code you can call [self performSegueWithIdentifier:#"someNameHere" sender:self]; to call the transition. This lets you do checks and validation before you move on to the next screen.
Just remember to click on your segue and name it (under identifier in the properties view). Then add the function prepareForSegue:sender: in order to transfer any variables or anything before it transfers (I rarely have to use this).

Displaying a Specific View in a UINavigationController Stack

In building my application which is a tab based application, from the first tab, the user has the option to view their profile information (which is specific to the app). SO have set up UINavigationController with following view controllers:
1 - Edit profile
0 - View profile (also the root view controller for the `UINavigationController`).
The flow I would like to achieve is if a profile has not been set up (i.e. the first time the application is run), I would like to go directly the Edit Profile View, which right now is the default behaviour since that view is at the top of the stack.
The problem I have run into is, if the profile has been set up, how would I go directly to View Profile. I have looked at the documentation for the UINavgationController, and it unclear about popping a view controller off the stack. The method popToViewController:animated return an NSArray of items popped from the stack. Does that mean those view controllers are no longer available, and/or is there a better method to go directly to the view controller that I want?
If you only have two views in the navigation controller, and View is the root view controller, you can make sure that View is the one that is shown by running popToRootViewControllerAnimated: immediately before or after that tab has been selected on the tab bar controller.
If you are in a case where you want Edit to show, run popToRootViewControllerAnimated: followed by pushViewController:animated: with the Edit view controller.
When you want to pop, you can use popViewControllerAnimated: rather than popToViewController:animated. (You only have two view controllers in this nav controller, so ther is only one that will ever be popped.)
This seems pretty simple, unless I have misunderstood your question.
The array of view controllers that are returned from the popToViewController:animated aren't needed by most programs. I haven't really found a need to use this method myself, and, as I said, it doesn't look like you need it here.

Resources