Refreshable
协议import UIKit
protocol Refreshable {
var refreshControl: UIRefreshControl { get }
func setUp()
}
extension Refreshable where Self: UIViewController {
var refreshControl: UIRefreshControl {
return UIRefreshControl()
}
func setUp(_ target: Any?, targetView: UIView, action: Selector, for controlEvents: UIControlEvents) {
refreshControl.addTarget(target, action: action, for: controlEvents)
if #available(iOS 10.0, *) {
targetView.refreshControl = refreshControl
} else {
// If targetView is TableView, no need addSubView. Just set refreshControl.
targetView.addSubview(refreshControl)
targetView.alwaysBounceVertical = true
}
}
}
类型的价值' UIView'没有会员' refreshControl'
类型的价值' UIView'没有会员' alwaysBounceVertical'
我知道UIView
没有refreshControl
和alwaysBounceVertical
。
那是什么类型的?
我可以为targetView
,UITableView
和UICollectionView
传递UIScrollView
。
答案 0 :(得分:0)
你将targetView
施放到UIScrollView
,UITableView
或UIScrollView
if let view = targetView as? UIScrollView{
view.refreshControl = refreshControl
//Other processes
}