Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Shifting UITableView down (UITableViewController)

I am just wondering whether or not it is possible to shift a UITableView down the page by, say, maybe 50 pixels. I know this would usually work if I had used a UIViewController then added a table view on top, but would I be able to do this and still keep it as UITableViewController?

like image 904
Michael M Avatar asked Sep 04 '11 17:09

Michael M


People also ask

What is the tableView in swift?

Overview. Table views in iOS display rows of vertically scrolling content in a single column. Each row in the table contains one piece of your app's content. For example, the Contacts app displays the name of each contact in a separate row, and the main page of the Settings app displays the available groups of settings ...

Why we use table view in swift?

In iOS applications, whenever we need to display the single column containing vertically scrolling content, we use tableview. The tableview can display multiple records (divided into rows), which can be scrolled vertically if needed. Each row of the tableview presents each record of the data source.


2 Answers

I had the same problem and the answer above didn't work. This did:

[self.tableView setContentInset:UIEdgeInsetsMake(50,0,0,0)];
like image 83
Flaviu Avatar answered Oct 24 '22 00:10

Flaviu


My solution is to override tableViewcontroller's method viewWillLayoutSubviews

- (void) viewWillLayoutSubviews
{
    [super viewWillLayoutSubviews];
    self.tableView.frame = CGRectMake(0,0,CGRectGetWidth(self.view.frame),300);
}

Works great and always for me with changing orientations and in all situations

like image 8
Nikolay Shubenkov Avatar answered Oct 23 '22 22:10

Nikolay Shubenkov