views:

812

answers:

4

I have a TabBarController, one of the tabs of which contains a sub view which is a navigationController. I am then loading into the navigation controller a view which inherits form UITableViewController.

My problem is thta for some reason the table view starts behing the navigation controller, not the top of the screen but about half way down the navigation bar, hence the top of the first cell in the table view is cut off.

Can anyone suggest how to move the UITableViewController down?

A: 

You can set the frame of the UITableView to an explicit X,Y position by setting the frame property on the view. Or you can change the same property using interface builder depending on whether you've added the tableview via IB or in code.

eg.

myTable.frame = CGRectMake(0.0, myTable.frame.origin.y + NAV_BAR_HEIGHT, myTable.frame.size.width, myTable.frame.size.height);

This will position the table myTable (which is a pointer to the UITableView) below the navigation bar, you may also need to adjust the height of the table accordingly. The height of the nav bar which I am indicating with a constant is 44.0.

I typically do this type of view adjustment if it has been necessary in the viewWillAppear of the view controller responsible. It's not common that you'll need to make this type of adjustment so it may be something you can fix by changing the way your views are being setup.

Without more details of how your view is setup it's hard to be more specific.

paulthenerd
A: 

ok @paulthenerd I tried what you suggested by doing

- (void)viewWillAppear:(BOOL) animated 
{ 
  self.tableView.frame = CGRectMake(0.0, 60.0, self.tableView.frame.size.width,   self.tableView.frame.size.height); 
}

but it did not move at all. As my view is a UITableViewController I used the ref self.tableView.frame the view is added to my navigationController by a button press

if (childController == nil) 
{
  childController = [[ResultsListViewController alloc] initWithNibName:@"ResultsListView" bundle:nil]; 
}
[self.navigationController pushViewController:childController animated:YES];
agough
A: 

Still not sure why this fixed it because it displays wrong in IB but I added a 20px Top Content Inset under Scroll View Size

agough
A: 

Fix it programmatically:

   - (void)viewDidLoad {
       UIEdgeInsets inset = UIEdgeInsetsMake(20, 0, 0, 0);
       self.tableView.contentInset = inset;
   }
sunkencity