iPhone App Dev - Loading a view into another view - iphone

I have a root view controller with just a simple navigation button that loads a questionview. When I use pushViewController a back button appears. Instead I want a custom button in the top right of the uinavigationcontroller and I want to remove the back button after the page transition.
how can i achieve this..

Take a look at UINavigationItem. You can accomplish both your goals by properly configuring your view controller's navigation item. Use the -setHidesBackButton:animated: to hide the back button, and the -setRightBarButtonItem:animated: to add your custom button on the right side of the navigation bar.

Related

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

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.

Persistent UIBarButtonItem on all navigation bars within tabbarcontroller

Ok so I have a tabbar iPhone application. The tabbarcontroller contains about 5 view controllers that are each embedded in their own navigation controller with the exception of 1 in which I just added a navigation bar in IB for a consistent look throughout the app. On every navigation bar in the app, I want a rightBarButtonItem that will open up the same modal view controller no matter where it is selected from. Similar to the "Now Playing" button in the music app, I want the button to stay on every navigation bar regardless of which tab I'm on or how deep I navigate into a navigation controller. How would I go about doing something like this? Is there some way I could simply apply the button to every nav bar in the same way UIAppearance can apply an image to every nav bar in an app? Thanks in advance for any ideas.
A simple approach would be to create a base view controller from which all your other view controllers extend.
With this in place, you could set up a UIBarButtonItem in the viewDidLoad method that attaches itself to the navigation bar and listens for events. From there, it would be quite easy to observe events and present either a modal view controller or push the appropriate view controller on to the navigation stack.
I use this approach for a "logout" bar button item that presents the login view controller when tapped as a quick alternative for users to sign out of their account.
The only down side to this is that each and every view controller that inherits from the base view controller will have the logout button in the navigation bar. Should you need other buttons or want to hide the default button, you need to replace it with another button instead.
It's a quick and easy approach and is also quite simple to remove if required as you can just change the header file to reflect the inheritance rather than sifting through several view controllers removing every instance of the button. It's also easy to maintain as you could overload the button target in any subclasses to perform different functionality when the event is fired.

Modal flip in tab bar tab, only the view, storyboarding

I have a tab bar with five tabs.
In one tab I have a mapview. I have an info button in the bottom right hand corner of the map. When a user clicks the info button, I want the mapview to flip to a view that has information about the mapview. I'd like a back button in the nav bar to flip back.
How can I do that?
I've managed to create a view controller and make a modal segue, but it doesn't keep the tab bar with it. Worse still, I created a back button on the flipside-viewcontroller with a modal segue back to the mapviewcontroller, and when you go back, the tabbar is gone!
I'm using a storyboard, and most tutorials I find use nibs and xibs. The more control-clicking I can do through the storyboard-IB and the less code the better. Any help is appreciated!
Once you have created in the backButton in the MapInformation view in storyboard, you can add the following to your MapInformation.h/m:
MapInformation.h:
-(IBAction)backButton:(id)sender;
MapInformation.m:
-(IBAction)backButton:(id)sender
{
[self.presentingViewController dismissModalViewControllerAnimated:YES];
}
After that, make sure to connect your IBAction in your storyboard(control-clicking).

How to disable UINavigationController?

I have a navigation controller-based app in which I would like to temporarily disable the navigation controller (top left button) at a certain point in the app so that the user can't get out of the view while I'm uploading a file. Is there a way to disable the "back" button so that users can't get out of the view?
You could hide the navigation bar entirely with
- (void)setNavigationBarHidden:animated:
in the appropriate views.
I don't know of an Apple-approved way to disable or otherwise interact with the back button.
In the view controller pushing into the view where you want to hide the back button (NOT in the view controller where you want the back button hidden), do:
self.navigationItem.hidesBackButton = YES;