Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

uitableview contentInset issue

I have strange issue with contentInsent. I am implementing "Pull & release" to refresh on UITableView and everything works fine, but in some cases I would like to display "loading" status without user interaction. So I thought I will simply use contentInset in the following way:

scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);

Everything works fine for 1 or 2 cells displayed - out of 3 possible on the view. However once the number of cells grows my banner at the top does not get displayed, at the same time manually scrolling works fine. Do I have to move the scroll besides moving content?

like image 445
Marcin Avatar asked Jul 21 '11 18:07

Marcin


People also ask

What is UITableVIew in Swift?

A view that presents data using rows in a single column.

What is contentInset?

The contentInset is how much the content is visually inset inside the scroll view. It is the custom distance that the content view is inset from the safe area or scroll view edges. contentInset allows you to specify margins or padding around the content in the scrollview.

Is UITableVIew scrollable?

Smooth Scrolling:- As a result, it affects the smoother scrolling experience. In UITableVIew, Scrolling will be smooth through cell reuse with the help of prepareForReuse() method.

What is tableview contentOffset?

Explaination of contentOffset of a UITableView : For example, if you have a table view of height 100. Its content may be more than it's view, say 150. contentOffset will tell the table from where in the content to start from. Say contentOffset = (0, 40) , the content will be shown after 40 of it's height.


1 Answers

OK, so I found the answer by playing a bit with different values. Turnes out that in the case described above besides setting contentInset you have to also setup contentOffset. In my case the following code worked:

scrollView.contentInset = UIEdgeInsetsMake(60.0f, 0.0f, 0.0f, 0.0f);    
scrollView.contentOffset = CGPointMake(0.0f, -60.0f);
like image 114
Marcin Avatar answered Sep 20 '22 06:09

Marcin