how to manage view controllers in a sequential pattern - swift - ios

I'm trying to implement sth like images below. there are some views that should be displayed in a sequential order and a bar above them shows the flow of tasks.
as it is shown, first profile view should be displayed. when the user clicks on Go to Next View Button second view (price view) should be displayed. the top bar shows the current view where we are in it. I've tried PagingMenuController already to create a menu with views and then disable scrolling. but PagingMenuController loads all views at the same time and also i don't know how to go to next menu item within child views. now I'm thinking of a container view might be helpful but i didn't use container view so far and i don't know it's good for my purpose or not.
also i want that top bar without swiping between views (only on buttons) and one enable view at the same time.
any helps would be apprectiated.

Your question is both broad and vague. My answer is also going to be fairly high level. I suggest you follow my outline, and if you get stuck on a particular step, post your code, tell us about the problem you're having, and we can help you fix it.
This is pretty simple. Create custom view controller. Give it a container view at the bottom that would contain the current child view controller. Use view controller transition methods to switch between child view controllers. You'll want to add layout anchors to each new child view controllers to pin all of it's view's edges to the edges of the container view.
Create a custom control on top to show the dot and highlight the title of the current view controller.
If you want the next/previous buttons to be on the child view controllers, put them there, and add a delegate property to all the child view controllers that points to the parent view controller, with next and previous methods.
BTW, in languages, like English, where text is laid out from left to right, I would think your first page would be on the left and the last page would be on the right. (I think it makes more sense for profile to be on the left and pay on the right.)

Related

Issue with Container Views in XCode

I have a simple project with one view controller. I want to add two views and create a transition between the two.
I've read that I must add the two views to a container view. When I drag the container view to the Document Outline, It appears at the same level as the views. I can't get it to be higher in the hierarchy. What am I missing?
Thanks!
Martin
"container view" in this case does not mean the container view you can select from the object library (this one you need if you want to embed viewcontrollers in other viewcontrollers) but just a regular uiview. drag a regular uiview from the object library to your viewcontroller and put the views you want to animate into this container uiview.
You need to explain what you want to do more clearly. You also need to be careful to use the right terms. Views and view controllers are different animals. Pretty much everything that appears on the iOS screen is a view: Buttons, labels, text fields, switches, etc are all views. The object that manages a whole screen-full of views is called a view CONTROLLER. Do not call view controllers views.
If you want a transition where 1 view controller gets fully replaced by another, you don't want container views. You want to use a navigation controller or maybe a modal segue. If you want a second view controller's view to appear inside your first view controller's views, then you want a container view.
If you just want to add additional views (text fields, image views, buttons, etc.) to your view controller then you just drag those objects onto your first view controller's scene in your storyboard.
In order to provide more help than that you're going to have to be clearer about what you are trying to do.

iOS table view in modal gets shorter every time view appears

Here's my set up:
I have a tab bar controller as my root view controller. In one tab, I present a modal on user action. The modal has a navigation controller, and view controller with a table view as it's root view controller. On another user action, I push another view controller. Every time I pop back to the table view, the content size seems to have shrunk. The table view gets shorter and shorter in appearance. This does not correlate to change in size of the table view. When I log i always get back the same tableView size and content size, but the content is getting eaten from below.
If understood properly, your setup follows this diagram:
Using exclusively Storyboard, Autolayout, the ViewLayoutAssistant.swift utility to emphasize views positions and sizes (what makes the crosshair), and exactly 0 lines of code, the odd behavior you describe above cannot be replicated.
As a solution, I propose you do just that: move your code to Storyboard, and bring-in your business logic in this flawless interface.

Split view in iPad

I am trying to create an iPad app wherein I need to maintain a split view throughout the app. In the split view, the left view is static and the rightview changes according to the selection of left view. The right view in turn might contain toolbars through which I can navigate to new views, But the left view always remains same.
I might have gone in with a split view but the problem is the left view is not table view but I want to use a customised view here. Is it acceptable to do this?
Please suggest if there are any better ways make a split view without using the default split view controller.
A split view controller can have any type of view in each of its 'panes', the standard template has a table view but there is no requirement to do so. Start with the template and then edit the master view controller so it's a subclass of UIViewController, you can also remove or edit the XIB as you require.

Designing view on top of multiple embed views

I have the task to design a application that has a main view which is always visible (it has a button on it's bottom side, and when pressed a image displays on top of all views), and a set of TableControllerView's that should appear under it, and the user needs to be able to navigate through them.
I know that you can embed a view inside another, but you cannot refer more than one view to it. The current way I'm trying to do now load one TableViewController inside the embed view, and when the user clicks the cell I manually load the other controller and add it as a child of the main view, which is the RootViewController. The problem with this approach is that the navigation bar gets stuck using the root view controller, so I have to manipulate the main navigation items on each subview transition, and second is that the frame for the second view I load is coming as it had full size, making some cells be under the main view button. This way doesn't uses segues for transition, so it makes the storyboard kinda useless.
I was thinking into using a TabViewController with it's tab hidden, but wanted to ask here for a better solution.
As you discovered, a TableViewController likes to fill up the whole screen (except navigation bars, tab bars, status bar, etc. which are official Cocoa Touch GUIs). When you want a table view to fill only part of the screen, you are supposed to use a UITableView but not a UITableViewController. You set your custom view controller object (subclass of UIViewController, not UITableViewController) as the table view delegate and data source. You will need to duplicate part of the functionality of UITableViewController in your custom view controller, but it's not a lot more than you have to do already to supply the data.
You should probably follow the standard design pattern and have separate view controller objects for each of the "pages" the user can navigate to. You just have a main button and image on each of them. But I could imagine why that might not give you exactly the effect you want.

Can I Have Multiple Hidden Views In A ViewController?

I know, this seems a bad solution, but I can't think or figured out how to make something better.
What I need to do is like a menu, iPad menu, with a toolbar up and bottom, and an image in the background. In the bottom toolbar, I'm going to have 4 different buttons. Every button is going to create the options menu in the middle of the screen. One button needs to display 3 options (buttons with images), another 4 options, another 8 options (for this, I'm going to use Scroll View and Page Control, because I'm going to need 2 pages), another 2 options.
I was trying to use subviews, one subview for every button, and I was added the options in the subviews. When I select one button, its subview was loaded, but when I tried to change its position and size, its buttons was missed, the subview was empty...
Now I'm going to have the 4 subviews in the ViewController, but hidden. When I select one button, the view is going to appear, and the others views are going to have hidden. This means, that all the subviews are going to have loaded. Is this convenient?
Is this method requires a lot of memory?
If somebody have another and better solution, I'll be completely grateful...
Thanks
Yes, you can have multiple hidden subviews within a view controller, but I don't think it's the most practical way of going about it.
You mention that the menus are to appear in the center of the screen. In this case, I think a better approach would be to create a separate view controller for each of your menus and then have your main view controller present them modally by using the view controller's modalPresentationStyle property. By doing this, you're saving yourself a ton of time by not having to write code that checks for which views are hidden and which aren't; you're letting the API do its job, so at most you'll need to implement a few methods such as dismissModalViewControllerAnimated:.
Check out Apple's documentation about UIViewController, and more specifically the section called "Presenting Another View Controller's Content".

Resources