views:

654

answers:

2

I've got a UITableView and I can't figure out how to get the size right.

My app is based on the Tab Navigator template. One tab's view loads a NIB that contains a Navigation Controller. The root view controller of the Navigation Controller has it's class set to a UITableViewController that doesn't have a corresponding NIB. The UITableViewController is declared as:

@interface MyRootViewController : UITableViewController <UITableViewDelegate, UITableViewDataSource> {

The problem is that the table view doesn't "end" at the right place on the screen. When you scroll all the way down, the tab bar cuts off about half of the text in the last cell:

alt text

All of the NIB files (for the view in the Tab Navigator and the Navigation Controller) have Bottom Bar set to "Tab Bar" in the Simulated Interface Elements section.

I've tried several variations of setting a new CGRect for self.view.bounds in the viewDidLoad methods of the UITableViewController, before and after the call to super, to no avail.

Any idea what I might be missing, or where to start looking?


Here's my current viewDidLoad (minus a few totally unrelated lines):

- (void)viewDidLoad 
{
    self.title = @"Table View Controller";


    CGRect frame = self.tableView.frame;
    NSLog(@"Frame height: %d", frame.size.height);
    frame.size.height -=100;
    [self.tableView setFrame:frame];

    [super viewDidLoad];

}

TheCGRect bit doesn't seem to do anything, and the log output is "Frame height: 0"

A: 

try this

CGRect frame = self.tableView.frame;
frame.size.height -= 50; //play around this value
[self.tableView setFrame:frame];
Morion
I put that code in viewDidLoad and it doesn't seem to do anything.Interesting thing is, if I putNSLog(@"Frame height: %d", frame.size.height);before the decrement, it prints 0.
Matt Miller
ok. make the UIView, not the UITableView the main view of your controller. and add your tableview and tabbar as subViews to your main UIView.
Morion
I haven't been able to work on this project this week. As soon as I get back to it I'll try that and let you know how it turns out. Thanks for your help!
Matt Miller
A: 

you should put NSLog(@"Frame height: %f", frame.size.height); instead of %d then NSLog can print number other than 0

NTK