我在一个UICollectionViewController
override func viewDidLoad() {
self.collectionView!.alwaysBounceVertical = true
let refresher = UIRefreshControl()
refresher.addTarget(self, action: "refreshStream", forControlEvents: .ValueChanged)
refreshControl = refresher
collectionView!.addSubview(refreshControl!)
}
func refreshStream() {
print("refresh")
self.collectionView?.reloadData()
refreshControl?.endRefreshing()
}
现在我需要它与一个UICollectionView
在一个UIViewController
我用谷歌搜索了一个小时,但还是不能正常工作。我很感谢你的帮助。
发布于 2016-02-12 21:58:50
在故事板中,您需要使用Ctrl +从集合视图对象拖动,将集合视图链接到适当的控制器文件。它需要通过@IBOutlet链接。
此外,您应该在按住Ctrl键的同时从集合视图拖动到情节提要上的视图控制器对象,并选择Data Source和Delegate,以便正确链接集合视图。
如果这对你有帮助,或者我误解了你的情况,请告诉我。
发布于 2016-06-13 21:22:47
在调用action方法时更改了新的快速代码,您可以像这样重写
@IBOutlet weak var collectionView: UICollectionView!
var refresher:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
self.refresher = UIRefreshControl()
self.collectionView!.alwaysBounceVertical = true
self.refresher.tintColor = UIColor.red
self.refresher.addTarget(self, action: #selector(loadData), for: .valueChanged)
self.collectionView!.addSubview(refresher)
}
func loadData() {
self.collectionView!.refreshControl.beginRefreshing()
//code to execute during refresher
.
.
.
stopRefresher() //Call this to stop refresher
}
func stopRefresher() {
self.collectionView!.refreshControl.endRefreshing()
}
发布于 2016-02-12 21:37:03
var refreshControl:UIRefreshControl!
override func viewDidLoad() {
super.viewDidLoad()
self.refreshControl = UIRefreshControl()
self.refreshControl.attributedTitle = NSAttributedString(string: "Pull to refresh")
self.refreshControl.addTarget(self, action: #selector(PricingPlansCollectionViewController.reload), for: .valueChanged)
collectionView!.addSubview(refreshControl)
}
func refresh(sender:AnyObject)
{
//DO
}
https://stackoverflow.com/questions/35362440
复制相似问题