我试图展示" man"和#34;女人"但是得到了#sigabrt"。有人请帮我解决我的问题
import UIKit
class ViewController: UIViewController, UIPickerViewDelegate {
@IBOutlet weak var pkvTest: UIPickerView!
var a : [String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
a = ["man", "woman"]
}
func numberOfComponentsInPickerView(pickerView : UIPickerView) -> Int {
return 1
}
func pickerView(pickerView : UIPickerView, numberOfRowsInComponent component : Int) -> Int {
return a.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return a[row]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
答案 0 :(得分:0)
您的前两个选择器视图功能名称错误。原因是您忘记将视图控制器声明为采用UIPickerViewDataSource。一旦你这样做,编译器就会唤醒问题并提醒你。
答案 1 :(得分:0)
试试这个。看起来你错过了viewdidload中的委托和数据源
class ViewController: UIViewController, UIPickerViewDelegate, UIPickerViewDatasource {
@IBOutlet weak var pkvTest: UIPickerView!
var a : [String] = [String]()
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
self.pkvTest.delegate = self
self.pkvTest.datasource = self
a = ["man", "woman"]
}