Reputation: 11159
I have a scrollview in a ViewController. The scrollview has a UIScrollViewDelegate
.On upon that i am adding a Tableview like below:
self.view.addSubview(self.tableView)
But when i am scrolling on tableview cells somehow the scrollview delegate is getting event, which is unexpected. What can i do to prevent that?
Upvotes: 0
Views: 151
Reputation: 853
The UITableView
is the subclass of UIScrollView
and that is the reason you are getting calls to the UIScrollViewDelegate
when you are scrolling the cell
s.
You can not prevent this if you want to have the scrolling enabled for the TableView
. I would suggest you check this condition inside your delegate method, for example:
func scrollViewDidScroll(_ scrollView: UIScrollView) {
guard scrollView != self.tableView else {return}
}
Upvotes: 1
Reputation: 467
That's normal because UITableView is a subclass of UIScrollView. Thus you should check if scrollView != self.tableView then do what you want to do inside the scrollView delegate method.
Upvotes: 0