Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIScrollViewDelegate. scrollViewDidScroll not getting invoked (Swift/Interface Builder/Xcode 6)

I'm trying to hook up a scroll view using Interface Builder, and the UIScrollViewDelegate.scrollViewDidScroll method isn't getting invoked on scroll.

In IB, I have a view controller that uses my PagedScrollViewController as a custom class. In that class, I have:

class PagedScrollViewController: UIViewController, UIScrollViewDelegate {
    func scrollViewDidScroll(scrollView: UIScrollView!) {
        println("scrollViewDidScroll")
    }
}

Unfortunately, that println is never getting invoked. I know that PagedScrollViewController is being connected correctly because if I add a viewDidLoad method, that gets invoked. Is there something extra I need to do to attach the delegate other than setting the custom class?

like image 634
Ethan Brown Avatar asked Dec 17 '14 22:12

Ethan Brown


1 Answers

Turns out I needed to attach the scroll view's delegate to the the controller. Here's what worked for me:

class PagedScrollViewController: UIViewController, UIScrollViewDelegate {
    @IBOutlet var scrollView: UIScrollView!

    override func viewDidLoad() {
        super.viewDidLoad()
        scrollView.delegate = self
}
like image 138
Ethan Brown Avatar answered Sep 30 '22 22:09

Ethan Brown