gpt4 book ai didi

ios - 无法识别的选择器发送到实例 [UIView setRefreshControl :]

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

在多个 VC 中使用自定义刷新控件的应用程序。但是,只有其中一个不工作并抛出主题错误。

自定义 UIRefreshControl:

class CustRefreshCont: UIRefreshControl {

override init() {
super.init()

let noColor = UIColor.clear
let lightGrayColor = UIColor.lightGray
self.tintColor = lightGrayColor
self.backgroundColor = noColor
}

required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}

我检查了其他 VC 中的代码,似乎没有什么不同。我假设错误可以在 MainStoryboard 以某种方式修复(即在 UIView 的检查器中?)

提前谢谢你。

编辑:提供附加代码:

声明:

let refreshControl = CustRefreshCont()
refreshControl.addTarget(self, action: #selector(PortfolioVC.refreshData), for: UIControlEvents.valueChanged)

// if it is iOS 10 and higher run new method
if #available(iOS 10.0, *) {
tableView.refreshControl = refreshControl
} else {
tableView.addSubview(refreshControl)
}

功能:

@objc private func refreshData (){
// Calculate elapsedTime
elapsedTime = Date().timeIntervalSince(lastRefresh)
convToInt = refreshRestrictSec - NSInteger(elapsedTime)

// If last refresh call was older then a minute
if NSInteger(elapsedTime) > refreshRestrictSec {

// Displaying text while updating
self.refreshControl.attributedTitle = NSAttributedString(string: "Updating data...", attributes: [NSAttributedStringKey.foregroundColor : UIColor.lightGray, NSAttributedStringKey.backgroundColor : UIColor.clear])
print(elapsedTime)
view.endEditing(true)
selectedCurrencies.removeAll()

// Pulling JSON data and updating selected Currencies
downloadCurrencies(completion: { (isComp, isErr) in
if Currencies.count > 0 {
syncValuesAtStored(cur: selectedCurrencies)
DispatchQueue.main.async {
calculateTotalWorth()
excludeNonePosses()
self.refreshControl.endRefreshing()
animateTableView(tableView: self.tableView)
self.collectionView.reloadData()
lastRefresh = Date()
}
} else {
print("Error on Refresh")
}
})

} else {
print(elapsedTime)
self.refreshControl.attributedTitle = NSAttributedString(string: "You can refresh \(convToInt) seconds later!", attributes: [NSAttributedStringKey.foregroundColor : UIColor.lightGray, NSAttributedStringKey.backgroundColor : UIColor.clear])
self.refreshControl.endRefreshing()
}
}

最佳答案

从 MainStoryboard 上的相关 VC (PortfolioVC) 删除并重新连接 tableView 的导出后修复了错误。因此,这一定是xCode的一个bug。

关于ios - 无法识别的选择器发送到实例 [UIView setRefreshControl :],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47836790/

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