Trevor Wood Trevor Wood - 2 months ago 20
Swift Question

My scrollViewDidScroll function is not receiving calls

I'm trying to check if a user is scrolling up and down on my app but it's not calling my

scrollViewDidScroll
method

Any ideas why it's not printing
received scroll
when I scroll up and down on the app?

import UIKit

class CreateAccount: UIViewController, UITextFieldDelegate, UIScrollViewDelegate {

@IBOutlet weak var scrollViewer: UIScrollView!
@IBOutlet weak var usernameTextField: UITextField!
@IBOutlet weak var emailTextField: UITextField!
@IBOutlet weak var passwordTextField: UITextField!
@IBOutlet weak var reenterPasswordTextField: UITextField!

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}

func scrollViewDidScroll(scrollView: UIScrollView) {
print("received scroll")
}

}


enter image description here

Answer

Add the scrollview delegate. Whenever you implement a delegate method you need tell it what controller to use, usually it will be self. It's caught me out a few times.

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view.   
    scrollViewer.delegate = self
}