Ste*_* PM 1 xcode uipickerview sigabrt swift
刚刚更新到Swift 3和xCode 8 Beta 4.
修复所有代码问题后,我现在有一个无错误的项目,但是当我点击我的前屏幕上的一个特定按钮时,它会抛出SIGABRT错误.
我确信它与目标页面上的UIPickerView元素有关,因为我已经删除,检查并重新添加了所有的segue和outlet以确保从那一方清楚一切.
控制台显示以下内容:
2016-08-02 18:59:46.607 ForceIt![38735:2895259] - [ForceIt_.DirectoryViewController numberOfComponentsInPickerView:]:无法识别的选择器发送到实例0x7fcd68c0c210 2016-08-02 18:59:46.618 ForceIt![38735:2895259]***由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [ForceIt_.DirectoryViewController numberOfComponentsInPickerView:]:无法识别的选择器发送到实例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])!)]
}
}
Run Code Online (Sandbox Code Playgroud)
numberOfComponentsInPickerView:是一个声明的方法UIPickerViewDataSource,但是你DirectoryViewController缺乏UIPickerViewDataSource符合协议的列表.
将类标题更改为:
class DirectoryViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDataSource {
Run Code Online (Sandbox Code Playgroud)
没有它,Swift无法numberOfComponentsInPickerView:从方法中暴露出来numberOfComponents(in:).
| 归档时间: |
|
| 查看次数: |
2687 次 |
| 最近记录: |