Boon
Boon

Reputation: 41470

How to reposition UITableView?

I have a UITableViewController and I want to add a navigation bar to it. So after the navigation bar (which works fine), part of the original tableView is being covered up by the nav bar.

I tried to reposition the table view using this:

self.tableView.frame = CGRectMake(0, 44 + 20 /* height of navbar + some margin */, 320, 416);

But the table won't position.

Upvotes: 0

Views: 531

Answers (2)

gerry3
gerry3

Reputation: 21460

You COULD set the nav bar as the header view of the table view like this (assuming you have the nav bar in a property called navBar):

self.tableView.tableHeaderView = self.navBar;

I am guessing this isn't what you want though (since the nav bar will scroll off when you scroll down the table).

Instead, you could change to a normal view controller & put the nav bar & a table view on its view (laid out however you want). You can add your own tableView property for the table view & make its data source & delegate your view controller & everything you have now should work just fine.

Upvotes: 0

rebeling
rebeling

Reputation: 728

self.tableView.frame doesn't work for me either, it throws an error, but

  1. I set the tableView in IB
  2. I create a caller in the h-file IBOUTLET UITableView *myTabli;
  3. connect FileOwner and tableView > myTabli in IB
  4. than I can call myTabli.frame = CGRectframe(x,y,width,height); in the m-File

works for me.

Upvotes: 1

Related Questions