How can I change the title of UINavigationBar Created in Interface builder - iphone

the issue is that I have created a UINavigationBar in interface builder and I want to change the title. The Navigation bar is not hooked up to my UINavigation controller. Is there any way I can accomplish this with the Navigation Bar as a stand alone from my Nib?
The second part of my question is more a general understanding of how the UINavigationBars work. I don't understand how the stack of navigation items works. for example what if i want to change the right button item to say "done" instead of "edit"? My understanding is that the left, center, and right bar button item are on a stack? but then how do I know which item is at what place in the stack. I'm sorry if I am missing something elementary here but I need some clarification on how the left, center and right bar button items are managed, and how the stack works into this. Thanks in advance.

You could use a custom titleView in the navigation bar, in which you have added a UILabel with the text of your choice.
Read the "Configuring the Navigation Item Object" section of Apple's View Controller Programming Guide for iPhone OS documentation for more information on how to customize the navigation bar.

create un IBOutlet of this UINavigationBar that you created in interface builder
#property (weak, nonatomic) IBOutlet UINavigationBar *navigationBar;
then change title with
self.navigationBar.topItem.title = #"My Custom Title";

UINavigationController is a subclass of UIViewController, but unlike UIViewController it’s not usually meant for you to subclass. This is because navigation controller itself is rarely customized beyond the visuals of the nav bar.
An instance of UINavigationController can be created either in code or in an XIB file with relative ease. It’s thought of as a stack: it has a root view controller, and then new view controllers can be pushed onto the stack (often when the user taps on a row in a table) or popped off the stack (often by pressing the back button).
The root view controller can be set in an XIB by dragging the view controller under the navigation controller, or in code by using initWithRootViewController when you create it.
The Navigation Stack
Four methods are used to navigate user through the stack:
– pushViewController:animated:
– popViewControllerAnimated:
– popToRootViewControllerAnimated:
– popToViewController:animated:

Related

Show UITabBar on UIViewControllers that are not part of the UITabBar?

I have an iOS app written in Swift with UITabBarController with 5 UIViewControllers. Now, I have a bunch of UIViewControllers that are not part of the UITabBarController. I'd like to be able to show that same tabbar but I have no idea how to do that. Any clue?
More details: This is one of the View Controllers that the tabbar has. I use storyboard references and split my view controllers into separate more manageable storyboards.
So, the big picture:
There's no initial ViewController since I use storyboardId to get to the initial Navigation Controller. From there we have a ViewController embedded in the same Navigation controller. In that ViewController, there are 2 Container views - one of the size of the bottom ViewController that contains the "hamburger" button that toggles the other Container View which has an embedded UITableView in. When a specific cell is selected it should go to Profile ViewController that's not even in the same storyboard. The segue is set to be Push. Either way, doesn't show the UITabBar on the Profile ViewController
how you doing?
I don't know if I understood, but you are trying to show tabbar after going to another screen, right? If the answer is 'yes', try to change your segue to show(e.g. push).
-----Edit-----
You can do with two ways:
Presenting Modally -> using Current Context
Use push(e.g.) with a navigation view controller, you can also hide the navigation bar if you go to Navigation controller -> Attributes inspector -> Navigation Controller -> Uncheck Shows Navigation Bar
Hope now it works!
Best regards

access UINavigationController from subclass of UINavigationBar

I have a UINavigationBar subclass, is it possible someway from that UINavigationBar to get my UINavigationController?
This is not a good design pattern. You should put the navigation logic into your view controllers. If you have controls (such as buttons) in your custom navigation bar, you should also handle these events in your view controllers.
Note that the UINavigationBar does not deal with the controllers (it should be the other way round), rather it deals with the UINavigationItems, which will look different according to if they are on top of the navigation stack or not.
There is a trick to make your custom navigation bar the navigationBar property of your view controller's navigation controller. Normally this is a read-only property. But you can put it into your navigation controller in Interface Builder in Xcode, and then change the class name in the inspector to your custom class. You will then be able to refer to your bar with the usual self.navigationController.navigationBar from within your view controller.

View Hierarchy with UIToolBar and UITabBarController

I have a rootViewController that is a UITabBarController. A UIToolBar is present in that controller since it has a SearchBar that is global to the app. In certain tabs, there should be specific UIBarButtonItems, or UISegmentedControl, along with the searchBar. In other tabs, there should be nothing in the toolBar, just a title.
What is a good way to lay out the view? Currently based on what tab is selected, the main toolBar from the rootViewController is either used as it is, have a UISegmentedControl added to it, hidden completely and replaced with another viewController that has its own toolbar, etc. To me, I'm thinking that each viewController that is present in its own tab can have its own ToolBar, and reference the global functionality, vs hiding/showing different toolbars.
sorry if this is a convoluted question. Just wondering if people had experience with this. Thanks.
The short answer is that there isn't really a good way to do this. If you're using a tab bar controller, the tab bar will always be visible along the bottom of your screen. Presumably each tab is a UINavigationController with a navigation bar at the top. There's not an appropriate place to put toolbar buttons in this layout.
A better design could be to abandon the UITabBarController and use a UINavigationController as your root view controller. Instead of tabs, you can have a table view with an item for each view of your application. Then you'll have room for a toolbar at the bottom of the screen. In fact, UINavigationController supports having a toolbar at the bottom. You just override the toolbarItems property to return the items that should appear in each of the child view controllers. You'll just need to set toolbarHidden to NO on the UINavigationController, and you're good to go.

Converting an Utility application (2 view controllers) to a Tab bar Application

As the title suggests, I have built an utility based app.
The app consists (at the moment) of 2 view controllers + a model class hierarchy.
The thing is , as I'd like to add some features to the app , I would like to convert it to a TabBar based application.
As a first step , I would like the first view to be the first view of the tab bar , and the flipSideView to be one of the other tab bar items.
Is there any "standard procedure" / "grocery list" for such tasks ?
I'm sure some of you have encountered the same problem , and would love some advice on "slicing up" the app , and "wiring it up" after creating a new nib file for the main window (is that the first step ? )
Thanks in advance.
I would probably start as follows (assuming you are using Interface Builder and using the standard Xcode utility app template):
Edit your MainWindow.xib file and drag a Tab Bar Controller object into the top level of your view hierarchy.
The default tab bar controller in IB includes two view controller items as examples. Click the first one and change its class to be your existing Main View Controller class.
You can also set the icon and tab bar title for the main view controller item by adding the associated Tab Bar Item that IB has already added to the view hierarchy.
Do the same for the second tab bar item setting the class for the FlipsideViewController.
Delete the old version of your Main View Controller from the NIB file and also remove the IBOutlet property from the Application Delegate (you probably also have references to the main view controller in dealloc which should be removed).
In your App Delegate add an IBOutlet property for the Tab Bar Controller as follows (don't forget to synthesise the property):
#property (nonatomic,retain) IBOutlet UITabBarController *tabBarController;
In IB wire up the tabBarController outlet from the App delegate object to the Tab Bar Controller object.
Finally to get the tab bar controller to show up in place of the main view controller change the code in application:didFinishLaunchingWithOptions: to the following:
[self.window addSubview:self.tabBarController.view];
This should get the basic tab bar app up and running and you can add additional view controllers to the tab bar.
Since you no longer want to flip between the MainView and FlipsideView you can remove the references to the FlipsideViewControllerDelegate from the MainViewController along with the info button and its IBAction method showInfo. Likewise in the FlipeSideViewController you should remove the done button from the view and its IBAction method as these no longer make sense when used with the tab bar.
so, step by step :):
1. declare UITabController outlet in your app delegate.
2. in MainWindow.xib: first drag the instance of UITabBarController in document window, then make connection from app delegate to that instance. now you can set MainViewController as UiTabBarController's first tab viewcontroller, then set FlipsideViewController as UiTabBarController's second tab viewcontroller.
3. in app delegate's appDidFinishLaunching replace [self.window addSubview:mainViewController.view]; with [self.window addSubview:theNameOfUITabBarControllerOutlet.view];. that will do the work. sorry, I don't know your background, that's why I'm not very specific about performing a particular action I decribe, so let me know if you find yourself stuck

UINavigationBar with TableView and Segmented Control inside UITabBar

I have a tabbar application. Second tab had a drill down table list with Navigation Controller. I also want to implement a segmented control inside a tool bar that shows different table entries as per the selected switch in segmented control. I am a little confused as to how to implement this?
Screen-shot -
This is the view in second tab controller an instance of the generic UIViewController. Blue Background is a UIView that contains a segmented control (1,2,3,4). The steel blue navigation bar at the top is a simulated UI Element from Interface Builder. I need to put a navigation Controller such that it has a list table view that changed depending on the switch selected in segmented control UI.
I have following options
Add UINavController as root controller for second tab directly with table view inside it. In that case how do I accomodate the UIToolbar having segmented control?
I add UISegmentedControl as part of the view of Second Tab's view controller and add navigation based table view as another element to that view. Is this doable? How can I add a nav based controller to a UIView and control the frame so that it does not cover the UIToolBar.
I hope I am making sense. Please lemme know if you have any suggestions. Thanks.
This is how I achieved it. In IB, in MainWindow.xib where I have a tabbarController, I made the class identity of the second tab to a UINavigationConrtroller. Then I made the main view Controller for second tab that had the segmented control and the Table View as a rootViewController to the NavigationController. This functioning exactly as I wanted. Thanks all for your help.
you can add UINavigationController in place of UIViewController in UITabbarcontroller and Put your UIViewController who haveing UISegmentControl in UInavigationController who add in UITabbarcontroller
in reading its looks confusing but try to implement its work
Step 1: xcode-->new Project-->tabbar application
Step 2: open xib of main window select tabbarcontroller and open inspector. in that you able to see list of view controllers change their class to uinavigationController.
if you need uinavigationController in second tab then change only secong tab class to uinavigationController
step 3: create new uiviewcontroller. open its xib and add uitableview and segment control to that.
Setp 4: now expand tabbarcontroller and check your second tab have navigationcontroller now add your uiviewcontroller in navigationcontroller's viewcontroller
According to your requirements you can't avoid working with code - I mean that you can't set everything by connections in IB.
I would create a UIViewController (let's call it container) that will contain the segmented control and the navigation controller.
You should set the second tab to be a view controller and point it to the container.
Container's view (XIB if you want) should contain the segmented controller that will be aligned to bottom and a containerView that will fill the rest of the view and will have its IBOutlet.
Container should also have a navigation controller member that will be initiated in viewDidLoad.
The table view that you talk about should also be built in its own XIB and have its own view controller that will be set as root view controller to the navigation controller...
Tell me if it's too confusing / complicated...