jac300
jac300

Reputation: 5222

Difficulties Re-positioning TableView in Xcode

I have an application in Xcode 4.5.2 that uses storyboards. I have a table view, and I want to reposition the table view so that it is a bit lower on the screen so that I can add an image and a button above where the table view starts. I have researched this question and although I have found a couple of suggestions, none have worked for me yet. The table view is accessed via a modal segue, so there is no navigation bar.

Here is what I have already tried:

1) I added a navigation bar and set its background to my image and then tried to add the button into the nav bar. Because Xcode would not let me resize the nav bar, my image was distorted as was my button and so I abandoned this effort.

2) I added a tool bar but had similar issues as I did with the navigation bar.

3) I attempted in code to move the table view down (thinking I could add the image and button in the free space above the table view). This did not work at all, my table view origin remains at the very top of the screen. but here is the code:

//called in the view did load method of the table view controller class

- (void)repositionTableView
{
  float yOffset = 75.0;

  CGFloat x = self.tableView.frame.origin.x;
  CGFloat y = self.tableView.frame.origin.y + yOffset;
  CGFloat height = self.tableView.frame.size.height;
  CGFloat width = self.tableView.frame.size.width;

  CGRect newTableFrame = CGRectMake(x, y, height, width);

  self.tableView.frame = newTableFrame;
}

Can anyone give me any suggestions on how to approach this problem? Thanks.

Upvotes: 1

Views: 1184

Answers (1)

Ben Lu
Ben Lu

Reputation: 3042

A lowered tableview

Make sure:

You created a UIViewController.

UITableView is the subview of self.view.

Autolayout is disabled.

And you can move it freely.

Upvotes: 1

Related Questions