Swift loading ViewController on TableViewCell Design - ios

As I understand it, one of the best ways of handling opening Views upon clicking a particular tableViewCell is by pushing to the ViewController.
However, this apparently only works if you only embed the ViewController in a NavigationController.
Would you then have to embed each individual ViewController in an Navigation Controller?
This sounds sort of repetitive and tedious - is this good practice?

This tutorial uses navigation controllers on all of the view controllers, but doesn't really say why
I just use one navigation controller, and it works fine for me. I've used one and had segues between multiple viewControllers including several tables as well as using buttons in some places, and still been able to navigate super easily. In main.storyboard, just select the first view that's going to be a part of it, then go to Editor>Embed In>Navigation Controller. Then, you just add in your segues (I believe they should all be Show(e.g. Push) segues to work correctly)
When running your app, there should be a bar at the top which can be used to go back (you can also edit the bar by adding other buttons or changing the color and title).
Here's some documentation from apple

Related

Keep state of navigation controller and only change view

I have an application with a drop down menu as the titleView of my NavigationController. When a user selects an item of the drop down menu, the entire view should switch contents, however, the NavigationBar should remain the same. The NavigationBar should not have to reload any data and the titleView should remain a drop down menu.
The original view upon opening the app:
The view upon touching the dropdown menu:
I currently see a few ways of going about this:
Set up a UIViewController for each option, perform the segue, and reload the data.
Why this is bad: I will have to set up a segue identifier for each ViewController, meaning if I have 15 options in my drop down menu, I will have 210 segue identifiers laying around. I will also have to reload all of my NavigationBar data.
Why this is good: I will have a clear area to set up each individual view.
Programmatically add and remove UIButtons, UILabels, and UIWhatevers as I need them.
Why this is bad: This will create a lot of code inside just one ViewController and things could get difficult to debug.
Why this is good: The NavigationBar never gets reloaded.
Add a container and embed a unique ViewController for each item as I need it.
Why this is bad: All of my work would still be in the main ViewController and I'd have to manage the logic of the embedded ViewController inside one Controller.
Why this is good: The NavigationBar never gets reloaded.
A completely different method suggested by someone else because I don't know the most efficient way of doing this.
So, in conclusion, what is the most efficient way to maintain state of my NavigationBar when switching my main content in my View?
Option 3 is the best out of the three you listed. Options 1 and 2 will get more and more complicated the more view controllers you want to add. Compare that to UINavigationController, UITabBarController, or UIPageViewController which do not need to be more complicated in order to handle 10 screens vs. 100 screens.
I would suggest creating a custom container view controller (Apple's Reference)
I see 2 immediate approaches to implementing this:
Subclassing UIViewController - this is how Apple's container view controllers are implemented
Subclass UITabBarController - I have done this successfully, subclassing UITabBarController to show a custom tab bar at the top instead of along the bottom.

How to link a separate storyboard to each particular tab in uitabbarcontroller?

I have an app which has 5 major user flows..each flow is a few screens linking to each other...so each flow warranties its own storyboard. Each storyboard starts with a custom view controller that is embedded in a navigation controller. So far so good.
Now all of this is "stitched" together via a UITabBarController. This is the most default UI design ever known to iOS.
But turns out I don't really know how to link from tabbarcontroller, which is in its own storyboard (that is set as the main one on code project) to any of the other storyboards.
This problem looks so! simple, so I think I am missing something utterly obvious, but I just can't figure out how to do it.
So how do I link from tab bar controller in storyboard 1 to the initial view controller in storyboard 2 when a tab is tapped?
You should do this in code. You can have the tab bar controller (tbc for short) and the controller in the first tab in the app's main storyboard, and in the app delegate, instantiate the other controllers using instantiateInitialViewController. Create a mutable array by copying the tbc's viewController array, add the other controllers you instantiated to it, and then set that array as the tbc's viewControllers array.
You have to add your viewcontroller programmatically in tabbar.

How to build navigation controller from existing view controllers drew in storyboard?

I have built some view controllers in storyboard like in the picture below
I already implemented the data inside them, modal segue is used for transitions in between. Now I just realise when I push "back" button, previous view won't be properly loaded. I figure I should switch to navigation controller and add those controllers in stack instead. But I don't know how to go from where I am now.
I think I should make changes programmatically because I found building navigation controller in storyboard won't have much variation in UI design (at least I don't know how to implement existing pages in that way). So what should I do to implement programmatically? Please help me, thanks!
Select Category View Controller and go to menu: Editor > Embed In > Navigation Controller. Then change segues style from Modal to Push.

master controller with buttons needs to load pageviewcontroller. master buttons not accessible after first load

I am new to xcode and IOS (and this board. First post).
I am completely flummoxed by a design problem and unsure how to approach.
I have three buttons, each of which calls a new array of pages that need to navigate horizontally with swipe gestures and have their own buttons.
The three buttons in the parent work exactly like a tab bar except they have to be bigger and higher than a tab bar would be. The called page arrays mostly work like a pageviewcontroller except that the pages need to have a button/indicator below to allow non sequential navigation. The target HAS TO LOAD WITH A SEGUE.
The problem I'm encountering is that using a modal segue to load a pageviewcontroller and prepareForSegue to keep the master/parent view controller visible results in my buttons being inaccessible. I assume its because I cant click thought the child view controller.
Secondly, I don't know if its possible to customize the page indicator dots of a pageviewcontroller so they can look like a bar with graphics.
Here are my specific questions:
Is it possible to load a view controller with a modal segue and still access my buttons? Can the child be resized?
can i customize the buttons/indicators in a pageviewcontroller. Can you point me to some code?
should navigation like this be done with some completely different approach? What about a view controller container?
Here's a diagram (cant post images directly yet)
I've found the answer to my second question: It seems that pageViewController's indicators are not customizable in any way. This rules out pageViewController for what I need.
9 Views in 10 hours. Is this not the best forum for questions like this or is there something wrong with my post?

iOS UINavigation Controller basics and custom back button

I make my first "serious" iOS app, and have some troubles with the whole UINavigation concept, but all in order. I look answers for my questions but don't find what I want, so here it is.
I want to make menu to a game, it would be look like so:
1) It's a RootViewController and it contain some buttons: new game, options, about.
2) I think it will be another view controller (It must appear when we touch new game button, and we see a menu when we choose game difficulty) the buttons is: easy, medium, hard
3) The game view controller (I think that this VC won't be the part of UINavigationController).
I have some concepts that I want to embody in this menu.
Here is it: I don't want to use UINavigationController Navigation bar, I won't use standard slide animation for UINavCon, I want to make my buttons "move to transparency" and come back with another menu from paragraph 2 mentioned above, it's not necessarily to change background or something else except menu items.
I want to use custom back button, and want to add it to the position I want and not to Navigation Bar.
I have some ideas about animation of menu items.
I don't know this:
It is better to use UINavigationController for my purposes or it's better to use normal ViewController?
If I make a UINavigationController can I see it's "child VCs (I mean not a root VC)" in my storyboard or it will be programmatically created thing and I must make it UI in code? If i must do this programmatically, could I make a segue from UINavigationController from storyboard, or I must do this from code too?
Could I make a UIButton, for example, and assign it functions from a normal UINavigationController back button from Navigation Bar?
Some questions might be dumb, but hope you won't judge me hard.
Okay, I'll do my best:
For custom animations, see
Yes, you make a custom segue class with the animation. try: joris.kluivers.nl/blog/2013/01/15/… and developer.apple.com/library/ios/#featuredarticles/… and cmumobileapps.com/2011/11/04/a-short-tutorial-on-custom-segues
Yes, i think a view controller is your best bet. But by the way, even if you use a navigation controller, you still use normal view controllers. A UINavigationController holds different UIViews, which go forward and backward on the navigation stack. Also, you will need to look up what you need to do to hide the navigation controller.
You can see the child view controllers in a storyboard if you create them their, but not if they are created programmatically, unless you just have the view in their.
[self.navigationController popViewControllerAnimated:YES] will "press the back button" programmatically, so just link the custom back button to a method that calls this.
If that doesn't cover all of your questions, just comment and I'll answer any more :)

Resources