UiTableview ContentInset

8.6k views Asked by At

I am working on very small app. In this app I am using UIrootviewController's table view to display some content in it. I want that content to be displayed at particular position so I am setting its contentInset. when I do it in viewDidLoad or in xib it is not showing any effect at first time. I have written it in shouldAutorotateToInterfaceOrientation function it is giving me proper location after orientation change but at first time it is showing table content at same location whatever may be the content insets values

here is my code for setting content insets

self.tableView.contentInset = UIEdgeInsetsMake(120, 150, 0.0, 0.0);

I have wrote this code inside viewDidLoad, and shouldAutorotateToInterfaceOrientation but it is not showing any effect when application starts. is there any other method to achieve this.

i even tried setFrame, but did not worked.

3

There are 3 answers

0
Arslan Faisal On

Put your code in the viewWillAppear method.

0
sust86 On

Try the following in viewDidLoad or viewWillAppear:

self.tableView.contentInset = UIEdgeInsetsMake(120.0f, 150.0f, -120.0f, -150.0f);
0
Abizern On

I think you may be confused about what method to use. If you want to set the position and size of the view you should set its frame.