UINavigationBar Above UITableView - iphone

I'm programmatically creating a UITableViewController class that shows a table view with a simple navigation bar (though without a UINavigationController, as there are no further levels to the table view hierarchy).
Here is the relevant code:
- (void)viewWillAppear:(BOOL)animated {
UINavigationBar *navBar = [[UINavigationBar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 320.0f, 44.0f)];
[self.tableView addSubview:navBar];
}
However, the navigation bar covers most of the first table view cell, and scrolls with the whole view.
How can I fixate the navigation bar above the table view, and keep it from scrolling through code?

The problem is that you are using UITableViewController. Switch to a standard UIViewController, add the tableview delegate and datasource methods, point the tableview to those methods, and then you do what you want to do. You could also add a UIToolbar in the XIB and create it that way if you wish.
If you really want a navigation bar, then use an NSNavigationView controller.

When you use a navigation controller, it takes care of this for you, but the navigation bar is just another subview. The remedy is to frame your table view relative to the navigation bar.
self.tableView.frame = CGRectMake(0,myNavBar.frame.size.height, 320, self.view.frame.size.height-myNavBar.frame.size.height);

Set the navigation bar's translucent property to NO:
self.navigationController.navigationBar.translucent = NO;

Having a hierarchy of data doesn't really drive whether or not you need to use a UINavigationController. There are three good reasons to go ahead and just use the UINavigationController.
You get the Navigation Bar for free, and the Nav Controller handles setting the proper frame of your root view controller when you set the nav controller's root view controller property to your view controller
If you one day wake up and say, "Hey! I want to add another layer of information to my awesome app!", you don't need to make any changes to the overall design (or, at most, minimal ones).
As my comment to #danh's suggestion implies, you're immune to whatever whacky changes Apple may decide to do with regards to nav bar height.

The solution to this behavior would be to add the UINavigationBar to the Parent View Controller's view:
[self.parentViewController.view addSubview:myNavBar];

Related

How to make transition from RootController to DetailController UITableview iphone sdk

I have a UITableView with some Cells.
I don't use NavigationController, so I'd like to use UIModalTransition to Switch from RootController, my TableViewcell, to my DetailView, but want to add a Navigation bar to attribute some actions, like Backbutton.
I don't want to use seguesTransition, I only used XIB File and any Storyboard.
I really don't know how to use the Modal Transition in TableView, anyone know how i can do it ?
Thanks.
have you tried
[self presentModalViewController:yourViewController animated:YES];
then you can set certain styles for transitions in it.
On the other view add a navigationbar and place a backbarbuttonitem and add an action to it to go back to your previous view.
Although why do you want to do it is unclear to me.
if you dont want a navigation controller on the first view, you can just set it to hidden.
self.navigationController.navigationBar.hidden = YES;
and then in the viewDidLoad of other view you can do the reverse i.e
self.navigationController.navigationBar.hidden = NO;
this is quite an easy way of achieving what you want with relatively less amount of code!!

iPhone UITableView overlaps UITabBar When Displaying it as a Subview

I have a Custom TabViewController that adds subviews to the current view depending on what UITabBarItem is selected. For the different subviews I have simulated a Navigation Bar and a Tab Bar so that the sub views match the format when they are displayed. The one sub view, which contains a UILabel, displays fine however the sub view with the UITableView overlaps the UITabBar. However in the Interface Builder I have sized the UITableView to not cut off the UITabBar.
Adding the subview in the TabViewController
[self.view addSubview:subViewController.view];
You haven't provided enough information to be sure, but I think you are adding the table view to the wrong view. Assuming that self is your UITabBarController subclass, you are adding the custom view in the view that covers the entire screen, including the tab bar.
Instead, you should be adding the custom views to the selected view controller's view:
[self.selectedViewController.view addSubview:subViewController.view];
This will limit the stuff you are adding to the tab bar controller's content area, and won't overlap the tab bar.
I'm not sure what you are trying to accomplish with this approach, though: it seems like it would make more sense to add subViewController to the set of view controllers that the UITabBarController manages, rather than messing around with the view hierarchy.
Also, there is nothing inherently wrong with loading views from a nib and then manipulating them in code. "Mixing styles" is not a problem.
As Legolas stated, it seems like you are mixing styles here. Given that it sounds like you need to push it from the code, you could try full instantiation of the object from the code, for example:
UITableView *table = [[UITableView alloc] initWithFrame:CGRectMake(x, y, width, height)];
table.delegate = self; //or whatever the delegate is
table.dataSource = self; //or wherever the datasource is
...then add it to whatever view you need to.
If that all fails, double check your nib and make sure you have the proper options set for whether a tab bar is being shown, nav bar, etc, as that will effect the size.

How to simulate the behavior of a UITabBarViewController?

I want to duplicate this controller same functionality without using it, this is because tab bar controllers are not customizable at all (fixed size, toggleable state tabs, etc...).
I want a customized "tab bar" that contains whichever view I want. And also I need to push view controllers leaving this customized tab bar fixed in its position.
I´ve seen lots off apps that do this, and I was wondering if using different UIWindow objects (one for the custom tab bar and other one for the content) was the best approach.
Any advice or guidance on this?
Thanks in advance.
Definitely not UIWindows - in an iPhone app there should only ever be one UIWindow.
I'd make a UIViewController subclass that had your new navigation bar ui at the top and a UIView underneath it. This view would be used to contain all the views of the controllers you are going to push in it. The view would have clipsToBounds set to YES to make sure your other controllers views don't overlap your navigation bar etc.
It would also have an array to hold the list of controllers that are currently inside it.
Your controller would implement the pushViewController:animated: methods etc to allow you to add other view controllers to the stack - you would add the new controller to your array and would add it's view as a subview of your controller's view.
However, it's actually quite a lot of work to make this well - a navigation controller will release child controller views on low memory warnings, handle rotation, animating on/off views etc. Are you 100% sure that this is what you want to do?
I've used a very simple approach. I subclass UITabbarController and during the init:
// Custom TabBar View
//
self.tabBar.hidden = YES;
MyTabBarView *myTabBarView = [[MyTabBarView alloc] initWithFrame:CGRectMake(0, 1024-44, 768, 44) // it'a an iPad app
configuration:configuration]; // an array of dictionary representing the view controllers
[self.view addSubview:myTabBarView];
[bottomBarView release];
then I load some view controllers with:
aViewController.hidesBottomBarWhenPushed = YES;
From MyTabBarView instance I perform on the UITabBarViewController:
setSelectedIndex:
In this way I've a customizable full screen application without pains.

Is that possible using "setAutoresizingMask" to make the view autoresizing after hiding/showing navigation bar?

I am doing this with the following:
[[self navigationController] setNavigationBarHidden:YES animated:YES];
and also I didn't use IB to create view objects. But my view did not auto-resize after hiding navigation bar(there was a blank area where the navigation bar used to be)
I am wondering if I could make it auto-resize only by "setAutoresizingMask", or do I have to use some hand-writing animation stuff?
myView.autoresizingMask will do exactly this for you. As soon as the navigation bar is hidden, the bounds of the superview of your views changes. This will auto-resize all subviews of the superview (and therefore all of your views) by having a look at each autoresizingMask of the subviews.
Short Answer:
Make sure your views use the autoresizingMask and you should be done.

Navigation bar not displaying

In a tab bar based app, I add a new UIViewController from tabview1 like this
[self.view addSubview:self.aView.view];
I created the nib for aView in IB. It is a view with a tableview and navigation bar. I have aView and bView, which are nearly the same and added to the parent the same way. The only difference is that aView has two sections in its tableview. Otherwise, the views are laid out the same.
For some reason, aView does not display its navigation bar. It also seems to sit a little higher than bView, since I can see a sliver of the parent view between the tab bar and aView. I've tried to find any differences between these two views that would cause this behavior but can't. What am I overlooking?
Depending on your needs you should be able to create separate nib's for each UIViewController then set each of these nib's to be loaded as the first view controller in each tar of the tabbar, or with the same nib's set these in each bar with:
- (void)setViewControllers:(NSArray *)viewControllers animated:(BOOL)animated
The following info from the Apple docs should help:
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW14
http://developer.apple.com/iphone/library/featuredarticles/ViewControllerPGforiPhoneOS/TabBarControllers/TabBarControllers.html#//apple_ref/doc/uid/TP40007457-CH102-SW15