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

标签 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 的检查器中?)

提前谢谢你。

编辑:提供附加代码:

声明:

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/

相关文章:

reference - 未定义对 `gtk_menu_bar_append'的引用

assembly - 使用uVision ARM编译器的未知操作码 'CBZ'

c++ - constexpr 环境中 std::array 上的 std::prev

ios - 使用 xib 创建可重用的 UIView(并从 Storyboard 中加载)

ios - 我的应用程序在尝试设置我的 map View 时崩溃

ios - 如何像 UIAlertView, iOS 那样提供不活动的背景效果?

ios - Xcode 5新文档将注释注释与属性或方法放在同一行

iphone - 我如何在我的 iphone 应用程序中验证 obj c 中的这个简单条件

iOS 辅助功能隐藏 "textField, double tap to edit"公告

ios - 共享扩展 UI 加载时间过长