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.
Related
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.
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.
Okay, so I want to be able to have a TabBar Controller with two Tabs (like the template in Xcode), but inside the Second tab, I want to have a button that takes the view to a Third View Controller. I want the Third View Controller to have a back button to the Second Tab, I don't want the Third View to retain the TabBar, but when I go back to the Second Tab I want the TabBar to return.
So this is what I actually did, and it doesn't work. I put a button in 2nd view and 3rd view, and I control clicked and dragged to the respective views, and clicked modal. Everything works, except when I go back to the 2nd view I lose the tab bar.
Pictures of what I am talking about:
Screen Shot of Xcode:
Screen Shot of iOS on 2nd view:
Screen Shot of after I click button to go to third view:
Screen Shot of after I Click button to go back to second view. ( lose tab bar !)
http://s13.postimage.org/78gqghflj/Screen_Shot_2012_07_09_at_2_03_41_PM.png
http://s16.postimage.org/gdwus4w6t/i_OS_Simulator_Screen_shot_Jul_9_2012_2_02_50_PM.png
http://s10.postimage.org/5uq3ste7d/i_OS_Simulator_Screen_shot_Jul_9_2012_2_02_57_PM.png
http://s8.postimage.org/gpmsx959x/i_OS_Simulator_Screen_shot_Jul_9_2012_2_03_54_PM.png
You don't need a separate modal Segue back to the Second View Controller, you can just dismiss the modal view controller when "Back to Second View" is clicked
[self dismissModalViewControllerAnimated:YES];
I'm confused on how storyboarding works.
So I created a simple app where the root view controller is a navigation controller.
I dragged a button to the the rootViewController of the NavigationController.
I dragged another view controller onto the screen, made it's background orange, and made it a subclass of OrangeViewController.
I dragged a connection from the status bar area of my rootViewController to the OrangeViewController.
I made this Segue Push and called it ShowOrange.
I created an action for my button that has:
- (IBAction)push:(id)sender {
[self performSegueWithIdentifier:#"ShowOrange" sender:self];
}
That's all it does. So when I press the button, it does show OrangeViewController. Then when I press back however, it keeps my background Orange. The title does change to ViewController, and there is no back button, but the background is orange. I was wondering why it does this?
My other question is a generic question with dragging segues. I seem to be able to drag it from the button itself, or the status bar. Is there a difference? What is really happening when that connection is made? Thanks.
Edit: Picture included
This particular answer is just for your second question:
Dragging from the button is analogous to setting that button's action to be performing the segue. Dragging from the view controller object (which is what I think is happening when you drag from the 'status bar', and would also happen if you dragged from the view controller while more zoomed out, or from the view controller in the list view), you are just setting it up to be used in code (in this case, it must have an identifier. The button segue does not need an identifier).
My iPhone app has a tab bar controller, and one of the tabs is a navigation controller. When the user double taps on the tab, it causes the navigation controller to pop back to the root view.
My problem is that some of the views in my navigation hierarchy have a specific bar button in their navigationItem associated with that view. So I'm programmatically setting the rightBarButtonItem based on what view was pushed to the navigationController. When the double-tap happens, it pops back to the root view, but not to the right button. The button seems to stay the same as the last view popped that had its own specific button.
So I have a mismatch of the root view with a bar button that goes with another view.
Is there a way to detect when the double tap action occurs? In that case I could reset the buttons on the nav bar to the correct ones. I tried doing it in viewWillAppear/viewDidAppear/viewDidLoad methods, but these don't seem to be called when the tab bar double tap happens.
The safest way to ensure that you always have the right button independent of how the view was made visible (e.g., by popping a child view controller, or by double-tapping the tab bar) is to set the button each time the view becomes visible. Thus, in your root view controller:
-(void)viewWillAppear {
//check button, change if desired
}