numberOfComponentsInPickerView

numberOfComponentsInPickerView

本文介绍了Swift 3 - SIGABRT 错误 - numberOfComponentsInPickerView:]: 无法识别的选择器发送到实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

刚刚更新到 Swift 3 和 xCode 8 Beta 4.

Just updated to Swift 3 and xCode 8 Beta 4.

修复所有代码问题后,我现在有一个无错误的项目,但在单击前屏幕上的一个特定按钮时会引发 SIGABRT 错误.

After fixing all the code issues I now have an error free project but it is throwing a SIGABRT error when clicking one particular button on my front screen.

我确定这与目标页面上的 UIPickerView 元素有关,因为我已经删除、检查并重新添加了所有 segues 和 outlet,以确保从那一边看一切都清楚.

I am sure that it is something to do with the UIPickerView element on the destination page as I have deleted, checked and re added all segues and outlets to make sure everything is clear from that side.

控制台显示以下内容:

2016-08-02 18:59:46.607 ForceIt![38735:2895259]-[ForceIt_.DirectoryViewController numberOfComponentsInPickerView:]: 无法识别的选择器发送到实例 0x7fcd68c0c210 2016-08-0218:59:46.618 ForceIt![38735:2895259] *** 由于以下原因终止应用程序未捕获的异常 'NSInvalidArgumentException',原因:'-[ForceIt_.DirectoryViewController numberOfComponentsInPickerView:]:无法识别的选择器发送到实例 0x7fcd68c0c210'

相关视图控制器的代码如下:

The code from the relevant viewcontroller is as follows:

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.

numberOfComponentsInPickerView: is a method declared in UIPickerViewDataSource, but your DirectoryViewController lacks UIPickerViewDataSource in its conforming protocol list.

将类标题更改为:

class DirectoryViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {

没有它,Swift 无法从方法 numberOfComponents(in:) 中公开 numberOfComponentsInPickerView:.

Without that, Swift cannot expose numberOfComponentsInPickerView: from the method numberOfComponents(in:).

这篇关于Swift 3 - SIGABRT 错误 - numberOfComponentsInPickerView:]: 无法识别的选择器发送到实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-07 17:06