this is probably quite simple.. but I don't know what's the best practice here.
i have a tabbarcontroller with 4 tabs, 3 of them should be a UINavigationController, the other one should also have the UINavigationBar to it but should not be a nav controller itself.
Now i want to give the UINavigationBar a tint color and an action button. I'd like to do this in the interface builder.
The navBar should always be the same one and i only want to create it once.
But where exactly would i do it? Would i create a .xib file with only the UINavigationBar in it and somehow link to that?
I'm very confused here, most tutorials only discuss the navBar for ONE navController but in my case i need the same bar for different ViewControllers..
NavBar comes with the navigationController or can come seperate. It is a subclass of UIView.
You cannot simply share your navBar with all controllers and the non-navigationController. I mean one instance of a navbar. You cannot even set the navbar for a navigationController. It is only readable.
In my understanding you are trying to make the navbar look the same in every controller, am I right?
So you can for instance subclass a UINavigationController and set it up as you want in the init method and init this subclass to add it to the view.
But what about the non-UINavigationController navBar?
Well, that's easy: Simply add your subclassed navigationController to that tab. You don't have to use it as NavController. You simply can add views to his view as to a standard ViewController.
Related
I've build a UINavigationBar into Interface Builder, and I have a NavigationController into my app. I'd like to make the one use the other to work. Just to manage the bar into IB and let the controller use it as its view (and adding by itself the Back button if needed), or in another way to do the same thing, let the NavBar use the navcontroller to adjust its display.
Do you see a way to do this ?
If not, I really don't see the use of the NavigationBar proposed into IB.
If you create the view controller in IB, you can give it a navigation item (UINavigationItem), and put your buttons in there. If you only create the view in IB and the controller is the owner (you use initWithNibName:bundle:), then you will either have to create the items programatically or put a outlet named navigationItem in your custom controller and connect it to a navigation item in the nib.
So my app's core is a tab bar. In each of 3 tabs is a UINavigationController subclass. Each one has a different type of table in it, which when a row is tapped, a detail is shown etc.
I currently have a 3 separate subclasses of UINavigationController, one for each tab. Then when a new tab is pressed, the table's controller is pushed.
I just read that you're not supposed to subclass UINavigationController. I'm not overriding any of UINavigation Controller's functionality, but I am overriding it's UIViewController functionality in viewDidLoad. Honestly that's just about it. It seems pretty silly, but Im unclear on how to get the Navigation Controller functionality without subclassing the way I have.
So how am i supposed to have a UINavigationController that I don't subclass? What is the approach that you're supposed to take to switch out the views when a tab is selected?
I'm pretty much a noob. Will Apple reject my app for subcalssing UINavigationController if im only overriding viewdidload?
I've heard folks say not to subclass UINavigationController, and instead 'present it modally.' I have used modal presentation a little bit, but I honestly dont' quite get how it would apply...
Thanks for your help!
What are you doing in viewDidLoad? What about do it in root view controller, not in navigation controller?
P.S. I think Apple will not reject your app for subclassing UINavigationController.
You should use categories to add extra functionality like that. It would look something like this:
#implementation UINavigationController (CustomViewDidLoad)
- (void)viewDidLoad
{
//code goes here
}
#end
You can add this to the bottom of the file that initializes the navigationcontroller
More info about categories (at the bottom): http://cocoadevcentral.com/d/learn_objectivec/
I want to have a UIView inside of a NavigationController that has 4 buttons. Clicking on any of these 4 buttons will push a UITabBarController that contains a NavigationController with a respective UIView.
Is this possible? Tweetie seems to do something similar.
On my application, I have a tab bar view controller, then inside of that, I have navigation controllers going to individual views in my interface builder. I believe if you just copy this format, it will work.(-> means connected)
Tab Bar View Controller->4 separate Navigation Controller->ui views
I hope this helps
I have a custom UITabBarController and I want it to slide out the old view and slide in the new view whenever a TabBarItem gets pressed. I looked at UITabBarControllerDelegate but it just offers me to decide if the view gets displayed not how (via shouldSelectViewController).
Is there a way to do that?
(My goal is to have a starfield background that looks almost the same on all the 4 views. It should look like the items get changed and the background just scrolls by a little)
Subclass UITabBarController and make it it's own delegate. Now you can intercept methods like tabBarController:shouldSelectViewController: and manipulate any custom views you have added to the tab bar. And if you add your starfield to the tab bar view, and then use tab controllers that have translucent views the common background can show through.
And you can even intercept tab bar controller methods directly like setSelectedIndex: to have even more control to let you fade things out. But just make sure that you call the super version of the method at some point if you do this so the tab bar remains functional.
I am using a UINavigationController to handle the pushing and poping of viewControllers in my app. Theres a section where i have a tab bar (not using UITabbarController) which is manageed by the same UINavigationController, i simply add the UITabBar to the navigation controllers view (by using addSubview).
The Problem:
I have some UIViewControllers with table views being pushed into the navigation stack, since my Tab Bar is part of the view and not the navigation stack the TableViews are cut off at the buttom because the Navigation Controller does not know of the tab bar because its in its view and n ot the navigation stack. Without a navigation controller i would just resize the ViewControllers view and it would work fine, but when i try to do that it seems like the NavigationCOntroller just ignores my frame and sets its own and therefore the table views are cut off. I found one solution which was to add some extra cells and hide them and that works sort of OK but its kind of hackerish, anyone have any suggestion of how to go about this in a different non -hackerish way?
Thanks
Alright, so i solved the problem. I had tried resizing the UITableView instead of the viewController before, but this did not work. I just realized though, that this did not work because i was using a UITableViewController which manages its own tableView and was not letting me change the frame of it (maybe i was changing it in the wrong place, tried in viewDidLoad, i bet if i did it after the call to [super viewDidload] it would have worked..o well). So I changed the class to a UIViewController and managed the table view in there, now it works good, thanks for the replies.
Try making the root view a UIView with a UITableView for a subview. Then add the UITabBar to the UIView instance. Now the UITableView won't know about the UINavigationController.