Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to detect scrolling of UITableView?

There is a similar question to this but answer is very general, vague.( Detecting UITableView scrolling ) Please don't dismiss. I am looking for concrete solution.

I have UITableView which has editable textfield and PickerView appears when another cell selected. What I need is to hide firstResponder or PickerView when user starts scrolling this UITableView.

So far in question Detecting UITableView scrolling there's a sugestion that you should subclass UITableView. IF you subsclass UITableView still internal/private UIScrollView is not accessible. How do I access UITableView's parent ScrollView (without breaking the law)?

Thanks.

like image 897
Rod Avatar asked Feb 09 '10 07:02

Rod


People also ask

Is UITableView scrollable?

UITableView is a subclass of UIScrollView that allows users to scroll the table vertically (the closely-related UICollectionView class allows for horizontal scrolling and complex two-dimensional layouts).

Can UITableView scroll horizontal?

You can add a UITableView to a UIScrollView and have it scroll horizontally.


2 Answers

You don't need to subclass UITableView to track scrolling. Your UITableViewDelegate can serve as UIScrollViewDelegate as well. So in your delegate class you can implement -scrollViewWillBeginDragging: or whatever UIScrollViewDelegate method you need in your situation. (as actually suggested in the question you mention)

like image 191
Vladimir Avatar answered Oct 17 '22 23:10

Vladimir


To expand on Vladimir's answer, this is how I implemented this solution:

In .h file:

@interface MyViewController : UIViewController <UIScrollViewDelegate> 

In .m file:

- (void)scrollViewWillBeginDragging:(UIScrollView *)activeScrollView {
    //logic here
}
like image 28
bbeckford Avatar answered Oct 17 '22 22:10

bbeckford