Presenting a UIVIew from a container view modally (nav bar missing) - iphone

I am a bit new to iPhone development and working on learning it on my own.
I have a view controller which contains 2 parts:
Image View - some picture + some text on top of it
Container view
the container view is now segued into a new controller view which I replaced with a collection view. The idea here is for this to hold some picture I can click on to get to another page yet.
So, with all that, I have things working fine. My main view shows the top picture + text and below is all the smaller pictures which are clickable and that take me to another view that is being presented modally.
The final view is a UIView that contains in it a imageView to hold the picture I clicked on the other view. This even works fine.
The issue is that I am trying to add a naviagtion bar on top of the new view which shows up fine in story board and I added a button to close it. But that for some reason does not show up when I run the application.
If I change the presenting mode to Push, I see the navigation bar show up with the back button as well, but my close button does not work there either (code added to dismiss the view correctly).
What am I doing wrong with the modal presentation?

If you want to present a view with a navbar modally, it has to have it own NavigationController.
So too have a NavigationBar in a modal displayed View, drag a UINavigationViewController in front of your ViewController, e.g.:
This is not needed in case of a push segue, as the pushed ViewController is still child of the original UINavigationViewController, wich is owner of the NavigationBar
The NavigationBar is managed by the UINavigationController, wich is on the parent-side.
So if you add Buttons in the Storyboard, you are adding these buttons to the NavigationItem, wich belongs to the ViewController.

Related

Navigation bar object in xcode 5 not showing back button and has no functionality

I have been trying to properly setup a navigation bar in one of my View Controllers for an hour now and have not found any working solutions.
I control-clicked on a button on my app's initial view controller(1st VC) and dragged to another view controller(2nd VC) and selected "modal" as the action segue.
I then added a navigation bar item to my 2nd view controller.
When I run my app on my iPhone, I can tap on the button on my app's initial screen and it will take me to my 2nd VC, and the 2nd VC does display the navigation bar, but the navigation bar does not have the default iOS 7 back arrow to let me go back to the app's initial VC.
I was under the impression that this could be setup exactly like I did above and that the back button functionality would be included by default.
Am I completely lost? Do I need to further customize navigation bar programmatically or with a tick box in the attributes inspector? Is "modal" the wrong action segue option?
I basically just want to have navigation bars at the top of a couple of my VC's so that the user can easily get back to the app's initial screen.
Thanks for the help.
Since you are presenting your second screen (2nd VC) as MODAL from your first screen (1st VC), you will not see the back arrow button on navigation bar. Your understanding about back button works for Navigation view controllers (push segue). For MODAL you need to put a cancel button on second VC's Nav bar and put a dismiss action for that.

Display whole ViewController within another ViewController's view

Im writing an application which the main view controller is a UIViewController. It has some icons in a grid and I want to dismiss (sliding down) this grid when one of the icons is clicked. This I've done already. The problem is: when the grid is dismisseed I want another View to come from the top of the screen. This view is in this same root view controller. But I want to display the content of other view controllers in this view. For example: I want this view to show a UINavigationController with a UITableView inside it, so the user can navigate through TableViews.
I'm doing this:
HorariosViewController *horarios = [[HorariosViewController alloc] init];
[vuashView addSubview:horarios.view];
HorariosViewController is a UINavigationViewController. It shows me only a blue NavigationBar and changes like self.navigationItem.title = #"Title" won't work.
Thanks!
You can show another view controller's views as subviews but their outlets and actions remain linked to their original view controller unless you write code to make new connections, so self.whatever shouldn't be expected to affect the other view controller's properties.
(Also, if HorariosViewController is a UINavigationController, it shouldn't be created as a UIViewController.)
One approach is to have the navigation controller already there, with the icon grid presented modally on top of it. (you can set the view up this way without animations, so the user doesn't see the navigation controller underneath).
Then, when it's time for the grid to go away, it can call dismissModalViewController on itself with animation.

Present UIViewController modally within a UIViewController that does not cover full screen

Basically once I dismissed the modal view, my customized UIToolbar no longer clickable.
Here is my design:
a customized UIToolbar at the bottom of the screen
top part of the screen is associated with a container view controller
[note] I added the top two items above into a root view controller and assigned to UIWinow's root view controller. The container view can be changed whenever toolbar items are clicked.
then, each toolbar item associated with a UINavigationController so that it's navigable.
within a UIViewController of a navigation, I present a view modally. The modal view does NOT cover the full screen as a result of the entire design...
after i dismiss the modal view, the UIToolbar items are no longer clickable.
I think the 'bug' is resided in where i presented the modal view, so I also tried to present modal view using root view controller, then there is also other issues...
maybe someone has more insight on this, that will be really appreciated :)
Thanks.
Try releasing the modalViewController as soon as its no longer needed. If you are using ARC, set it to nil. Allocate a new one when a modalView is needed.

Invisible back button when view controller pushed onto navigation controller

I'm using a navigation controller to drill into a detail view when a cell is tapped. When I push my view controller onto the navigation controllers stack, I expect to see a back button that I can tap to pop the previous view off the stack.
The issue is that the back button isn't visible, but when tapping where it should be returns me to the previous view. What's the problem?
Ensure you have set a title for the master view - for example in viewDidLoad add this -
self.title = #"The Title";
Weirdly, if there is no title for the parent view controller on the stack, rather than show an empty back button, the iPhone will not display a button but will allow taps on the area where it should be.
This bugged me for a long time!
At least as of iPhone 3.0, you can also avoid the dreaded invisible back button by setting a title on the root controller's navigation item in your main window's nib (MainWindow.xib in wizard-generated projects).
Lets see if this helps you.
I had the same issue where I used a navigation based application and set up my search, rotation etc..
BUT, when I clicked on the table cell I was directed to the next view but that view did not have a back button present.
I tried to add a title to the back button but that did not work so this is what I did.
I opened the mainWindow.xib file and added a Bar Button Item to the group of other items inisde the window (where the file's owner is located). I then assigned an image to the button (you can add text here if you want).
Then I clicked on the Navigation Item and hit command 2 to open up the Navigation item connections
and chose the back bar button item and dragged it to the bar button item I wanted to use for my back button. And there you have it.

Sliding Up/Down a UINavigationController

I have an app that uses a UINavigationController as its main way of showing data.I want a Settings screen to pop up, but I also want to be able to push new views for Settings. From what I've found, I can't use a UIViewController do to this. How can I present a view by sliding it, and also have content pushed onto it?
You can display the view for your view controller subclass either by presenting it modally (slides from the bottom and takes over the whole screen) or pushing it onto the navigation stack with animation (slides from the right and keeps the navigation bar).
In either case, you control the content of the view using your view controller subclass. Typically you update labels and controls in the viewWillAppear method.