Can i add a Navigation Controller to a ModalViewController? - iphone

I want to present a Modal view in the middle of the screen in on an iPad. This view will have a search bar and a table view. It will present search results. This is up and running.
Now i need to add a navigation controller so that upon touching a row in the above table view, a detail view will be pushed in from the right to allow the user to determine if this is the item he wanted.
I tried adding a navigation controller to my modal view but it doesn't display and i couldn't find a tutorial for this.
Can someone please give me a hint?
EDIT: I'm starting to think that i first need to push a modal navigation controller and then add the tableview to this, is this the correct approach? Can someone please give some details on this if that's the case?

Yes this is possible. You have to present the NavigationController modal. Your ViewController will be the rootViewController of the UINavigationController.
I posted some code in Adding UINavigationController to existing UIViewController

Related

Swift How to go Back to previous view controller when bar button tapped

I'm new to Swift programming and here is a really simple question.
How can I go back to previous view controller when a bar button is tapped?
My view controllers are all tableviews, none are navigation controllers. I inserted a bar on top of my table view and added a bar button item and created an action outlet but don't know what code to put inside. I found some responses on stackoverflow that are using a popviewcontrollerAnimated but when I write popviewcontrollerAnimated it says unresolved identifier. I have four viewcontrollers atm, ViewController,SecondViewController,ThirdViewController and FourthViewController.
I'd appreciate any help. Thank you!

Is Initial View Controller does work?

I have a viewcontroller and a tab bar controller. I want to change view controller as initial view controller and create a segue to show tab bar controller.
I have tried to set the new initial view controller. There are 2 ways. First, check the tick box "Is Initial View Controller". Second, drag the arrow to new screen. It does not show any error, but it shows the tab bar controller as usual and I can't find the view controller either.
Anyone know how to what is going on. Please tell me to fix. Thanks
You need to use a UINavigationViewController and connect it up in the hierarchy in a similar fashion to:
The leftmost view is the "view" that you mention, which needs to show the UITabViewController.
I've added a button for ease of use.
The next along (send from the left) is the UINavigationViewController. No settings on here need to be set etc... it's pretty much "plug and play" as to put it.
The next view (third from the left) is the UITabViewController (with corresponding views to it's immediate right).
The connection between the UINavigationViewController and the UITabViewController is "rootViewController" as the Tab View is the "root view controller" e.g. the primary view controller.
The segue between the first view, and the navigation view controller is merely a "show" segue. I liked directly between the button and the navigation controller in Xcode.
Hope this mash-up helps!
Edit I wrote a quick mask up of what I posted in the images for you to play with: https://dl.dropboxusercontent.com/u/61211034/Stackoverflow/NavgationViewController.zip
Based on your storyboard's image, looks like you don't have any NavigationController embedded to your root LoginViewController, try this:
Select your LoginViewController on your storyboard
Then in xcode Menu bar at the top, go to Editor -> Embed in -> Navigation Controller (as you can see in the image below)
Then your NavigationController will be set as your Initial View Controller, and see your LoginViewController be displayed and work as expected your segue.

Tab Bar mysteriously disappears?

Attached are two images. The first shows my current main.storyboard, and the second shows my problem when I run the app. I have a tab bar controller that has two tabs. On the first tab there is a button. When pressed, the button goes to another view controller with content. At the top is a Navigation bar with a back button. After viewing content, I press the back button, and am back on the original page with the button, but the tab bar is missing. I have seen a few answered questions, but it appears they made their tab bar in the view controller instead of the storyboard. Another says that I should never return to a previous view unless I use an unwind segue. Is this true? If so, how do I set up an unwind segue. If not, how do I fix this problem otherwise? Thank you.
http://i.stack.imgur.com/IYmX2.png
http://i.stack.imgur.com/7slt5.png
The problem is in the wiring of your ViewControllers. You have probably embedded your UITabBarController inside the UINavigationController and not the other way around.
A correct layout looks like this in Interface Builder :
To reproduce:
In Interface Builder drop a UITabBarController. This will come with 2 UIViewController's already wired in.
Pick one of the UIViewController's (let's call it VController1) and click on Editor / Embed in / Navigation Controller. This wires the VController1 to live inside a UINavigationController that is inside the UITabBarController
Add a 3rd UIViewController next to VController1 Let's call it VController3
Wire in a segue between VController1 and VController3, for example with a button.
I hope that's clear enough
Try Linking the button in your viewcontroller (other than the views of the tabbed bar controller) with the tabbed bar controller. Create a segue that links the button with the controller of the tabbed bar application

Switching Views within UITabBar View

I have created an UITabView application. Each view selected from the bar is a seperate controller with own nib file. I switch between them succesfully.
In the first view I have two buttons (check out the screenshot). When clicking them I want to switch to another views which are the parts of the current view controller. I use:
[self presentModalViewController:anotherViewController animated:NO];
That switches the view, but hides the UITabBar. How to keep the bar on the screen after the switch?
P.S. Sorry for the blurred image. I am not allowed to share to much info.
Well I think you are misusing the modal view controller. For a problem like this I'll say you should put them in a view controller stack using UINavigationController. Instead of making each tab a UIViewController make it a UINavigationController, then you can push and pop view controllers on it, which still show the tab bar.
See http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UINavigationController_Class/Reference/Reference.html
use: tabBarController.selectedViewController = newViewController
edit: UINavigationController is not needed here.

Search Controller is not showing up in TableView Controller

I draged and dropped Search Display Controller onto my TableView Controller. When I push that TableView controller from RootView controller, Search Bar is not showing up on the top of the TableView. I used the same technique for the rootview controller and I could see SearchBar on the top of my TableView.
What could possibly cause that problem?
I'm not sure this is the same problem, but I have asked a similar question before, perhaps that can help you.
How do I add an UIView above a TableViewController
Cheers
/Jimmy