gpt4 book ai didi

ios - 如何将拉动刷新 Controller 添加到 ScrollView ?

转载 作者:行者123 更新时间:2023-11-29 06:00:25 25 4
gpt4 key购买 nike

您好,在我的应用程序中,我想将拉动刷新 Controller 添加到 ScrollView 。我编写了以下代码,但没有得到任何响应。

每当我 ScrollView 时,都不会调用添加目标方法。

@IBOutlet var scrool: UIScrollView!
var refreshControl = UIRefreshControl()

override func viewDidLoad() {
super.viewDidLoad()
// Add refresh control for the Home page scroll view.
self.refreshControl.tintColor = UIColor.appcolor
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: #selector(refresh(sender:)), for: UIControl.Event.valueChanged)
self.scrool.isScrollEnabled = true
self.scrool.alwaysBounceVertical = true
scrool.addSubview(refreshControl)
}
@objc func refresh(sender:AnyObject) {
// Code to refresh table view
self.getHomePageApi()
refreshControl.endRefreshing()

}

最佳答案

您好,当我在 viewwillappear() 中编写此代码时解决了这个问题,除了 viewdidload() 函数之外,它可以正常工作。

var refreshControl:RefreshControl!    
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
refreshControl = RefreshControl()
refreshControl.addTarget(self, action: #selector(refresh), for: .valueChanged)
scrool.refreshControl = refreshControl
}

@objc func refresh()
{
// Code to refresh table view
refreshControl.endRefreshing()
self.getHomePageApi()

}

关于ios - 如何将拉动刷新 Controller 添加到 ScrollView ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54730638/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com