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

时间:2017-12-15 17:01:03

标签: ios compiler-errors storyboard

该应用程序在多个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的Inspector中?)

提前谢谢。

编辑:提供了额外的代码:

Decleration:

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()
    }
}

1 个答案:

答案 0 :(得分:1)

从MainStoryboard上的相关VC(PortfolioVC)删除并重新连接tableView的插座后,修复了错误。因此,这必须是xCode的错误。