Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UITableView contentInset makes table view scroll horizontally in addition to vertically

I'm creating a UITableViewController in code and pushing it on top of the navigation stack. It's table view is intended to just show a simple list of text items.

I need to add some contentInset to my table view which I add in the init method of my UITableViewController

self.tableView.contentInset = UIEdgeInsetsMake(7.0f, 5.0f, 7.0f, 5.0f);

However, when I load the table view it seems the left and right contentInset have actually stretched the width of my table view by 10. I'm now seeing a small horizontal scrollable area. I don't want any sort of horizontal scrolling on my table view. If I remove the contentInset code, my table view behaves plainly i.e. simply provides for vertical scrolling. How I can keep just like that but with my contentInset in place? I tried reducing my contentSize.width by 10 in viewWillAppear, it had no effect.

This seems to be a duplicate but with no acceptable answer: UITableView ContentInsets scrolling content horizontally

In the mock I have marked the desired contentInset with dashed line ---

enter image description here

Thanks.

like image 520
George Burdell Avatar asked Apr 28 '13 07:04

George Burdell


1 Answers

I ended up setting just the top and bottom insets. To achieve the left and right inset look and feel, I created custom cell as wide as the screen. But the actual cell content was restricted to a slightly narrower subview within the custom cell. Thus, there was space leftover on the left and right of the subview.

like image 183
George Burdell Avatar answered Sep 27 '22 22:09

George Burdell