Last row in UITableView is obscured by UITabBar - iphone

I have a UITabBarController that has a list of UINavigationControllers assigned to the 'viewControllers' property.
Each UINavigationController has a custom UIViewController as its 'rootController' and this custom UIViewController loads its 'view' from a .xib file. This 'view' contains a UITableView (and some other controls that are displayed when the data for the UITableView is first downloaded).
It works fine to begin with - I can see the table view for the first view controller when the first tab is selected, changing tabs displays the other table views - all is good.
My problem is, when I select a row on one of these table views a new custom view controller is instantiated, told to hide the bottom bar when pushed and then is pushed on to the navigation controller. Again - this works as expected. I see the new sub-view and the tab bar is hidden.
The problem is when I return to the previous view, the final row in my UITableView is now obscured by the tab bar (which has correctly reappeared). It seems the process of hiding the bottom bar and then showing it again when returning to the previous view has confused things.
Has anyone encountered this? Any idea what I might be doing wrong?

Check that your UITableView has not the UIViewAutoresizingFlexibleHeight (in IB, see the picture below).
alt text http://www.quicksnapper.com/files/5161/20375276064A0C11D2C33A4_m.png

Related

Subview loading from storyboard

I am beginner in ios development. I created a tab bar controller in storyboard. In one of the tabs, I added a table view with custom cells in storyboard with a map view on top created in code. When user presses on the map view, it slides down pushing down the table view. All is fine except when I go to other tab and come back to the tab, the table view is back up with its frame from storyboard. Can some one suggest how to prevent this?

Add Tabs To MasterView Controller Project

I created a MasterViewController project with a tableView, now I'd like to add some tabs to this. I tried to just drag and drop the tab bar into the MasterViewController and the tabs show, but they are linked the the last cell in the tableView.
Is there any way to make the tabs stay in place so they are always displayed? What I am trying to accomplish is to give the user buttons to push to organize the data in the tableView, so I'm open to other suggestions.
Here are the pictures:
You need to have your controller be a UIViewController, not a UITableViewController (where the table view is the controller's self.view, and is full screen). If you use a UIViewController, you can add a table view, and size it such that you have room at the bottom to add the tab bar. In that case, both the table view and the tab bar are subviews of the controller's self.view. The way you're trying it, the tab bar is added to the table's scroll view.
It sounds like you added it as a subview of the table view, so as the table view scrolls it scrolls too. Look at creating a container view to hold both the tableView and tab bar / segmented control / buttons positioned below it. You will need to make the controller a subclass of UIViewController instead of UITableViewController.
Alternatively, use the navigation bar to add some edit button(s), either to enter an editing mode which shows controls on each row or where the buttons actually edit the currently selected row.
Tab bars are container controllers and are used to present a different mode of your application. If you want to only organize your tableview data, my suggestion is to use UISegmentedControl.

UISearchBar displays in the root view but not in any other view on the tab bar

I have implemented the search bar for the table in the first tab and this works fine and filters fine, however, with the same code and the xib linked up all the same etc on the second tab it no longer displays the search bar. Is there a simple reason to this?
Separate out the UISearchBar into its own class and then call it from the multiple views. It is not meant to be reinstantiated for each view controller.
Yes, there is a simple reason—the search bar is a subview of your main view, so when that view gets swiped off screen, it disappears with that view. To fix this, you'll have to add the search bar to the view that holds your tab bar controller—you'll probably have to put it in MainWindow.xib. You can still connect it to your tab bar controller if you need to—just add a reference to in the XIB.

How do I add a Navigation Bar to a UITableViewController in Interface Builder?

Interface builder does not let me click and drag a Navigation Bar onto a Table View Controller!!! It is super frustrating.
All I want is a table view with an edit button (done in interface-builder). If this is not possible, then how do I add a navbar progammatically?
From the outline view, make sure your Table View Controller is selected.
Then go to the Editor menu, and click on the Embed In submenu, and choose Navigation Controller and voila. You have your navigation controller pointing to your tableview controller with a relationship built in.
For a table view with an edit button at the top, use a UINavigationController, with a UITableView as the rootView. That means you're going to make a custom UITableView subclass for your table view, and use that as the rootView of your UINavigationController instance. (Programatically, it's set with UINavigationController's -(id)initWithRootViewController. It's also settable through IB.)
Then, in your UITableView subclass, uncomment the following line:
- (void)viewDidLoad {
[super viewDidLoad];
// Uncomment the following line to display an Edit button in the navigation bar for this view controller.
self.navigationItem.rightBarButtonItem = self.editButtonItem;
}
and voilà, your UINavigationController's view shows up as a table view with an edit button on the right side of the navigation bar.
Since the controller is at the top of the stack, there's no "back" button on the left, so you can use self.navigationItem.leftBarButtonItem for whatever UIBarButtonItem you create.
I agree that it's difficult to figure out how to do things like this in Interface Builder, but luckily it is possible to add a Navigation Bar and Bar Button Item to a Table View this way. Here's how to do it:
Drag a blank View (an instance of UIView) from the Library to the area near the top of the Table View. As you drag near the target area, Interface Builder will highlight it in blue to show you where to drop the View. Let go, and the View will be added as a subview of the Table View's header view.
Drag a Navigation Bar from the Library and drop it on the blank View you just added.
Drag a Bar Button Item from the Library and drop it onto the Navigation Bar.
EDIT
The problem with the above approach is that, as Bogatyr points out, the Navigation Bar will then scroll along with the Table View. Apple recommends using a custom subclass of UIViewController that owns both the Navigation Bar and an instance of UITableView resized to fit. Unfortunately, that means you would have to implement the UITableViewController behavior needed by your UIViewController subclass yourself.
Another approach that seems to work well is to create a custom subclass of UIViewController that owns a blank background view containing the Navigation Bar as well as a blank content view (an instance of UIView) that fits under the Navigation Bar. Your custom subclass would have an outlet pointing to an instance of UITableViewController in the same nib file.
This has the advantage of allowing all the view components to be created and configured in Interface Builder, and doesn't require implementing UITableViewController methods from scratch. The only detail you'd need to take care of in the Table View Controller's parent would be to add Table View as a subview of the parent's content view in viewDidLoad.
The parent could implement the action methods for the Navigation Bar's button items, and implement the delegate pattern if necessary.
From iOS6 onwards, you can use container view. So what you have to do is take View controller, add the navigation bar to it, then add a Container View to same view controller. It will automatically, add the new view controller link to your container view. Now simply delete that, and your table view controller in the story board. Now embed the table view controller to container view by control drag. Hope it helps.
First add a navigation controller and put the table view controller (as root view controller) onto the navigation controller. This is how it is done in Code because I don't use IB.
Why in the world you can't drag a navigationItem into a .xib file with File's Owner set to a subclass of UIViewController and hook the navigationItem up to the UIViewController's navigationItem outlet is beyond me. It seems like a real hole in IB / XCode integration. Because you can certainly drag an instance of ViewController to a xib file, and drag a navigationItem into the ViewController, and then set the title and barbuttonitems that way.
So if you want to define your UITableViewController subclass object's navigation bar in IB, you have to create your TableVC object in a xib file (not the one .xib file that contains the tableview for your UITableViewController, though!). You then either hook the TableVC object up to be an outlet of another object (like your application delegate), which works if you need just one instance of your TVC throughout the lifetime of your app, or if you want to dynamically create instances of your TableVC in code you load this extra .xib file manually via loadNibNamed:owner:options method of the NSBundle class.
These steps worked for me in iOS 9:
Add a View Controller to the Storyboard. Make UITableViewController as base Class.
Add a Navigation Bar object onto view controller at the top.
Add a Table View below Navigation bar.
Add a Table View Cell into Table View.
Add constraints.
This is the other easy way ;
Choose your TableViewController screen on storyboard.
Click Size Inspector symbol on the right menu and find Simulated Size
Change Fixed to Free Form
You can add navigation bar easily.

iPad: Custom Toolbar for UISplitViewController

How exactly does one go about implementing a custom toolbar for the main table view section of a split view?
The program I am writing for the iPad is landscape only so the split view has a static table view along the left side, and at the top is the toolbar with a title. It is this toolbar I would like to change. I have created the split view controller, table view controller, and detail view controllers programmatically so I should have reference to the toolbar object. The only thing is I don't know how to reference it so I can overwrite it with my custom toolbar.
Is it the split view controller that creates this toolbar? Or the table view?
Any ideas?
It's a navigation bar, not a toolbar. You'll want to investigate the navigationItem property of the UIViewController responsible for the view with the navigation bar. This is an instance of UINavigationItem; see the documentation here: UINavigationItem.