刚刚更新到swift 3和xcode8beta4。
在修复了所有代码问题之后,我现在有了一个无错误的项目,但是它在点击我的前屏幕上的一个特定的按钮时会产生一个Sigabt错误。
我确信这与目标页面上的uipickerview元素有关,因为我已经删除、检查并重新添加了所有的segue和outlets,以确保从那一边看一切都很清楚。
控制台显示以下内容:
2016-08-02 18:59:46.607强制![38735:2895259]
-[forceit_uu.directoryviewcontroller numberofcomponentsinpickerview:]:发送到实例0x7fcd68c0c210 2016-08-02的无法识别的选择器
18:59:46.618强制![38735:2895259]***由于
意外异常“nsInvalidArgumentException”,原因:
'-[强制目录视图控制器数字组件选择器视图:]:
无法识别的选择器发送到实例0x7fcd68c0c210'
相关viewcontroller的代码如下:

import UIKit

var forceSelectedForTabView = String()
var forceSelectedPositionInArray = Int()

class DirectoryViewController: UIViewController, UIPickerViewDelegate {


    @IBOutlet weak var forcePicker: UIPickerView!
    @IBOutlet weak var selectedContactLabel: UILabel!
    @IBOutlet weak var selectedPhoneTextView: UILabel!
    @IBOutlet weak var selectedWebsiteTextView: UILabel!

    //function for the number of columns in the picker
    func numberOfComponents(in pickerView: UIPickerView) -> Int {
        return 1
    }

    //function counting the array to give the number of rows in the picker
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
        return forcePickerData.count
    }

    //function displaying the array rows in the picker as a string
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
        return forcePickerData[row]

    }

    //function allowing the font and colour of the picker to be changed
    func pickerView(_ pickerView: UIPickerView, attributedTitleForRow row: Int, forComponent component: Int) -> NSAttributedString? {
        let titleData = forcePickerData[row]
        let myTitle = NSAttributedString(string: titleData, attributes: [NSFontAttributeName:UIFont(name: "Verdana", size: 25.0)!,NSForegroundColorAttributeName:UIColor.black])
        return myTitle
    }

    //function returning the selected row from the picker
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) {

        forceSelectedForTabView = String(forcePickerData[row])
        forceSelectedPositionInArray = forcePickerData.index(of: forcePickerData[row])!


        self.selectedContactLabel.text = issiData[Int(forcePickerData.index(of: forcePickerData[row])!)]


        self.selectedPhoneTextView.text = phoneData[Int(forcePickerData.index(of: forcePickerData[row])!)]


        self.selectedWebsiteTextView.text = websiteData[Int(forcePickerData.index(of: forcePickerData[row])!)]

    }
}

最佳答案

numberOfComponentsInPickerView:是在UIPickerViewDataSource中声明的方法,但您的DirectoryViewController在其一致性协议列表中缺少UIPickerViewDataSource
将类标题更改为:

class DirectoryViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

没有这个,swift就不能从方法中暴露numberOfComponentsInPickerView:

关于swift - Swift 3-SIGABRT错误-numberOfComponentsInPickerView:]:无法识别的选择器已发送到实例,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38728094/

10-12 00:18
查看更多