Imagine, there is a UIViewController with a UIScrollView in it. At the top of the view there is an UIImageView, some UILabels and other things. Furthermore, there is a UITableView which content is Dynamic Prototypes. I attach a picture to make it clear:
I haven't got a static amount of cells in the UITableView so it could be scrollable. My problem is the following: the UITableView scrolls in itself but I want to scroll the whole View. What is the best possibility to do that?
Possible solutions I've founded today
1) The first thing is: I create a UITableViewController and declare a header section in which I include all my labels, images etc. programmatically (I would love to use the interface builder for that...)
2) Another solution is to calculate the height of the view. I tried the best to do it like this way - but: without success. If this is the best way to do that: Can anybody give an example?
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.
To scroll to the top of our tableview we need to create a new IndexPath . This index path has two arguments, row and section . All we want to do is scroll to the top of the table view, therefore we pass 0 for the row argument and 0 for the section argument. UITableView has the scrollToRow method built in.
Cache can basically solve most performance problems. TableView needs to know the height of the Cell to layout the Cell. You need to know the height of all the Cells to know the height of the TableView itself. Therefore, every time you call reloadData, you need to calculate the height of all the Cells.
I would ditch the UIScrollView
and just use a UITableView
. You can add a UIView
object as the tableHeaderView
of the UITableView
just by dragging it in in Interface Builder. Now since everything is part of the UITableView
hierarchy, everything will scroll together as expected.
You could also try setting delaysContentTouches
to NO
on your scrollView
. Depending on your setup, this may make the scroll view respond to the touch first instead of the table view.
From Apples UIScrollView
Docs:
delaysContentTouches
A Boolean value that determines whether the scroll view delays the handling of touch-down gestures.
@property(nonatomic) BOOL delaysContentTouches
Discussion
If the value of this property is
YES
, the scroll view delays handling the touch-down gesture until it can determine if scrolling is the intent. If the value isNO
, the scroll view immediately callstouchesShouldBegin:withEvent:inContentView:
. The default value isYES
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With