Reputation: 55
I have a TextView and a Tableview in UIView. Im trying to detect either scrolling is textview scrolling or tableview scrolling?There is any code for this? Thanks for any help in advance :)
Upvotes: 1
Views: 1091
Reputation:
UITextView
and UITableView
are both subclasses of UIScrollView
, so both of them triggers the UIScrollViewDelegate
methods.
assume that __scrollView
and __textView
are your respective UIScrollView
and UITextView
,
Overriding UIScrollViewDelegate
method
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if ( scrollView == __scrollView ) {
// UIScrollView is scrolled
}else if ( scrollView == __textView ){
// UITextView is scrolled
}
}
Upvotes: 0
Reputation: 4824
There is UIScrollView
already embedded in UITableView
and UITextView
Reference
- (void)scrollViewDidScroll:(UIScrollView *)scrollView;
Upvotes: 0
Reputation: 5186
UITableView & UITextView are a subclass of UIScrollview. So all the UIScrollView you will get when you scroll UITableView. Here you get a list of UIScrollView method.
Upvotes: 0
Reputation: 3708
Use func scrollViewDidScroll(_ scrollView: UIScrollView)
delegate and check. Set UITextViewDelegate
and UITableViewDelegate
and check in method
Example:
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
if scrollView == tableView {
}
if scrollView == textView {
}
}
func scrollViewDidScroll(_ scrollView: UIScrollView) {
if scrollView == tableView {
}
if scrollView == textView {
}
}
Upvotes: 1
Reputation: 4375
UITextView
& UITableView
both are implemented by using UIScrollView
You can identify the which control scrolling & direction by implementing the UIScrollViewDelegate
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView {
if ([scrollview isKindeOfClass: [UITextView Class]]) {
//UITextView
} else if ([scrollview isKindeOfClass: [UITableView Class]]) {
// UITableView
}
// Identifying direction
CGPoint point = [scrollView.panGestureRecognizer translationInView:scrollView.superview];
if (point.y > 0) {
// Dragging down
} else {
// Dragging up
}
}
Upvotes: 1
Reputation: 2207
UITableViewDelegate conforms to UIScrollViewDelegate, so all you need to implement these methods -scrollViewWillBeginDragging and -scrollViewDidScroll
- (void) scrollViewDidScroll:(UIScrollView *)scrollView {
if (scrollView == myTableView){
// Your logic here.....
}
if (scrollView == textView)
{ // Your logic here..
}
}
Upvotes: 1