我正在尝试检查用户是否在我的应用程序上上下滚动,但是没有调用scrollViewDidScroll
方法
当我在应用程序上上下滚动时,为什么不打印 received scroll
有什么想法吗?
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")
}
}
最佳答案
添加滚动 View 委托(delegate)。每当你实现一个委托(delegate)方法时,你需要告诉它使用什么 Controller ,通常是 self
。它把我抓了几次。
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
scrollViewer.delegate = self
}
关于swift - 我的 scrollViewDidScroll 函数未接听电话,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/39549398/