iOS Swift How to go back from a split view to a normall view controller - ios

I have a simple iOS app that I want to use a split view in, but I also need some normal view controllers(non Split view). So I have my story board setup like this:
Story board
I will add more views to the base navigation view depending on what they click on in the first view some will go to other standard views and one will go to another split view. as I can not add the split view to my base navigation view (get an error saying it had to be the root view) I replace the root view with the split when the button is clicked using a replace Segue.
My question is: how do I get back to the first view once I am in the splitview? can I somehow had a custom back button to the detail view title bar to go back? Or am I going about the whole thing wrong? Any help or a push in the right direction would be great!

I ran into this problem myself. Unfortunately, UISplitViewController cannot be added as a child of another view controller. I must be the root view controller of a window. From the docs: When building your app’s user interface, the split view controller is typically the root view controller of your app’s window. The way I got around this was just creating a container view controller in my storyboard: It ended up looking like this:
It's pretty basic, just adding the two view controllers as children of the parent view controller. You can control the width of each on straight in IB.

Related

iOS custom view across all view controllers

I would like to have custom view set in one screen and have it across all view controllers in my application.
I find solution with using Container view. So I create RootViewController and I give it Container view and set my original MainViewController as embed in container. I added view to RootViewController and in first view controller (MainViewController) it looks good.
The problem is when I go to another view controller by Push segue. New view controllers covers whole screen (which is okay) and covers custom view too. I was thinking that it could help if I add Navigation Controller with root MainViewController and this navigation controller would be embed in RootViewController but the result is same. I set Navigation bar as hidden (same for status bar) because I want to be hidden.
So where could be problem? Or how would you add custom view to all screens? This custom view should work as global (I am using NSTimer and counting time) so I solution with inheritance isn't for me.
You can use application window and add this custom view as subview whenever required. I have used it in one of my app to show notifications (if there area any) and it works great.
Get handle to Application Window and add subview to it. Custom view can be created from a singleton class or App delegate.
You could try it the other way round. Make a view which will never change inside your root view controller and a container view and just change the content of the container view depending what u want to display next to your unchanging view.

Can't add navigation bar to scene: Root view controller issue?

I'm still struggling with navigation bars and just can't work out how to edit or verify that I have a navigation bar on my view and I would appreciate any help.
I have a project with another set of scenes similarly comprising of a navigation controller and three associated view controllers (connected via segues and main table view embedded in the navigation controller) and I was able to add a navigation bar manually in interface builder to the outer view controllers that were segued to the table view controller.
But in this set of scenes the navigation controller is set up as the root view controller for the table view.
I have another set of scenes. A navigation controller and two related view controllers - both table view controllers. I embedded the first table view controller in the navigation controller and I then added a second table view controller to this (for a new screen I want to add to my app) and I connected this second table view controller to my first table view controller by way of a show segue (just like I did yesterday with other set of scenes).
Can I set this other navigation controller as the root controller also?
Like, can I have two root view controllers in a project?
It looks to me like there is a navigation bar visible (see screenshot below) on my new table view controller but I can't click in to it to edit it to add a title to it.
But does a navigation bar and exist, and if so, why can't I click inside it and use it?
I was told in an answer to a previous question that you have to add a navigation bar manually to your storyboard scene to any additional view controllers. I did that yday and it worked. But today when I tried to add a navigation bar by dragging onto scene it wouldn't let me do this.
Here is the screenshot:
Try adding push segue(which is depreciated) and than change it to a show segue(between your tableviews). This is a workaround I use in my apps.
Ran into the same problem. Had a good fallback position, I am doing a tutorial that came with example programs completed and working so the first thing I did was see if it was a version glitch between 6.3.2 and 6.4. Turned out the earlier project worked just fine.
So what I did was simply drag the 'Item' in the sidebar and moved it under the Root View Controller!
I've experienced the same issue.
However, by saving and closing the project then reopening it, the Navigation Bar title is then able to be edited. Prior to closing/reopening the project the field could not be edited.

Partial segue to show settings view

in the google maps app for ios. When you select the settings button, it will show you a view of options such as "traffic", "public transit", etc.
My question is how this is done on ios.
I tried following this tutorial but it says that it won't work on uinavigationviewcrollers. I have seen this partial segue of the the view in apps that use a navigational controller. How do they create that?
It's not a partial segue. It's not a segue at all, it use of containment view controllers.
Instead of a single view controller which transitions to a different view controller image one single master view controller. For simplicity, we'll say this view controller has two views (of the root), both of which cover the the whole screen. For this example let's think of them as "main" view and "menu" view.
Other than these two empty views, the view controller has no content. That's because this view controller does nothing other than manage other view controllers which get stuck into the two views. It will have a couple methods manage them, like presentInMainView:(UIViewController *)viewcontroller and presentInMenuView:(UIViewController *)viewcontroller
When the program starts running the master view controller will programmatically add the map to it's "main" view. The map view controller now cover the whole screen and looks and acts like it's the top level view controller, but it isn't. It's contained. At some point some taps the settings button and the map view controller will make a call to it's parent and say presentInMenuView:... and the master view controller will then load up a second view controller into the menu view. The menu view could even be located off the left side of the screen and the master view controller animates the menu view frame to side it right covering the whole screen. Assuming the menu view controller only has content which covers the left half of the screen you'll see the map view controller hiding behind it.
That really only scratches the surface, lots can be done with container view controllers. You could create a container which lets you brings up a dozen different views all populated with view different view controllers. You could size and arrange them on all over the screen and each child view controller could still only have to deal with it's own contents.
For more info there is the Apple Developer Guide and the WWDC 2011 Videos where it was introduced (session 102)
I used SWRevealViewController For similar type of sidebar animation.They given the good example of how to use SWRevealViewController also please try it once.

Add StatusBar Like View in App?

In my app I want to add a view much like the status bar, always onscreen at the top of each of my view controllers, displaying application wide data.
I really have no clue how I might achieve this so any suggestions would be really helpful. I;m sure someone must have chased this idea at some point?
Thanks.
What you're willing to do is fairly straightforward since iOS 5 using view controller containment, it allows you to embed child view controllers in a parent view controller.
In your case I would create a custom container view controller with two subviews: the content view and the statusbar-like view. The content view should display your current root view controller by adding it as a child view controller to your container view controller and adding its view as a subview to the content view. The statusbar-like view can then be used to display information that will be visible everywhere in your app.
You might want to read this documentation for further details:
Creating Custom Container View Controllers
You can create your custom view and add it as a subview to your keyWindow. This way it will always be visible. Another option is if you have tab bar controller or a navigation controller as your root view controller, then you can add that view as a subview to their respective view and it will always be visible.

IPad Split View Implement in Another View

I am creating a iPad App and it has several views to load data,but for one view i need to add split view. I dont need split views in other views. They are just detail pages. I search Through the net and found lots of tutorials based on iPad split view. But the problem is they all are creating a project as Split view project or they create a window base app and add slipt view to the delegate. I dont need to do that, I need to implement this split view only for one view. Is There any way to overcome this problem?
You can add the split view inside a Navigation Controller.
Even if the Split View is a container view controller and Apple recommends in the documentation that all containers should not be embedded in other containers, adding a split view inside a navigation controller works correctly and I never noticed any side effect in doing it.
Basically what you should do is:
- in the app delegate create a UINavigationController and use it as root view of your application window
- hide the navigation controller navigation bar if you don't want to see it (showing a split view with a main navbar on top is not nice looking...)
- then add your view controllers inside the navigation bar.
Example: imagine you have this application views sequence:
FIRST VIEW (full view = detail page)
SECOND VIEW (split view)
THIRD VIEW (full = detail page)
So you can represent FIRST and THIRD as standard view controllers (full screen), while SECOND will be a split view. Your app will be initialized by creating the main navigation controller, adding FIRST on it as top controller and using the main navigation controller as window's root view.
Than use the navigation controller push, pop methods to switch between these views or change the navigation controller "viewControllers" array directly if you don't want the recommended push/pop methods.
If you need to add special behavior to the navigation controller based on the type of view on top, just register your app delegate as navigation controller delegate (or a "main controller" object dedicated to this if you don't want to complicate your app delegate).
I am not 100% sure, but it seems to me that you can't use a SplitView just somewhere in your view hierarchy.
The Apple intended way is to use the SplitViewController as the top level controller. The left side of it can include a drill down mechanism with a navigation controller so you are ably to drill down hierarchies and the right side will present details for the item you select on the left side.
If you need a view with some kind of split mechanism in it, you probably have to code it yourself. Or even better: find some other mechanism you can use in your UI.
How are you switching your view hierarchies now? Maybe you could integrate your existing UI into a SplitViewController?

Resources