AlexanderN
AlexanderN

Reputation: 2670

How to move an entire UITableView down programmatically

I have a tableview that I need to push down and resize smaller. I cannot use the content inset for this as its not the content I need to push down. I need to actually move the entire tableview down 44px.

What I have tried:

CGRect tableViewFrame = self.tableView.frame;
tableViewFrame.origin.y = 44;
self.tableView.frame = tableViewFrame;

Thank you in advance!

Upvotes: 1

Views: 2899

Answers (3)

Shankar BS
Shankar BS

Reputation: 8402

you can not move UITableviewController down, instead of this you can do like this

  1. Create a file having UIViewController subclass with XIB.(create a seperate view controller)
  2. Add UITableView as subview
  3. Then wired up the UITableview , delegate and datasource.
  4. Implement delegate protocols for tableview
  5. use your code as it is ..

it works fine.. :)

Upvotes: 0

hamid
hamid

Reputation: 115

Convert your UITableviewController to a UIViewController and then add the tableview as subview in your nib. Also don't just change the y coordinate of tableview. instead define a new frame for your tableview e.g. self.tableView.frame = CGRectMake(x,y,width,height)

Upvotes: 1

The Kraken
The Kraken

Reputation: 3158

You need to change your UITableViewController to a regular UIViewController and then add the table as a subview. Then, just manually implement the UITableViewDelegate and UITableViewDataSource protocols in that view controller. After doing this, you can move the table view with your above code like any other subview.

Have a look at this answer for an example.

Upvotes: 7

Related Questions