我知道这个问题存在很多问题,但我仍然无法使用我的具体代码。对不起,如果这是noob问题。这是我的完整代码。如果我在viewDidLoad中断,我的委托和dataSource设置为自行运行而没有问题。在任何已实现的UIPickerViewDataSource函数运行更改之前,此事件之后会立即发生异常。我在下面包含了调试。
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate {
var listingTypesList:[String:Int] = [
"Bench": 0,
"Squat": 1,
"Dead": 2
]
@IBOutlet weak var listingType: UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
listingType.delegate = self
listingType.dataSource = self
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return listingTypesList.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
var listingTypesArray = Array(listingTypesList.keys)
return listingTypesArray[row]
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
2017-10-03 20:41:36.038930-0400 Lifting Trainer [328:19327] - [UIView numberOfComponentsInPickerView:]:无法识别的选择器发送到实例0x107811de0 2017-10-03 20:41:36.041055-0400 Lifting Trainer [328:19327] *由于未捕获的异常'NSInvalidArgumentException'终止应用程序,原因:' - [UIView numberOfComponentsInPickerView:]:无法识别的选择器发送到实例0x107811de0' * 第一次抛出调用堆栈: (0x181697d38 0x180bac528 0x1816a51f8 0x18ae5fcc4 0x18169d6e4 0x1815830dc 0x18acf93a8 0x18acf8504 0x18acf85e4 0x18aaa476c 0x18aaa445c 0x18aaa3918 0x18aaa3770 0x18aaaf39c 0x18aaae5c4 0x18aaab608 0x1a03c04fc 0x18ab1b068 0x18ad0a954 0x18ad0f6e4 0x18af9d454 0x18b26d1f0 0x18af9d0b8 0x18af9d928 0x18b7066e8 0x18b70658c 0x18b4829c0 0x18b617fc8 0x18b482870 0x18b26c850 0x18ad0de28 0x18b1116ec 0x183d39768 0x183d42070 0x105a6945c 0x105a75b74 0x183d6da04 0x183d6d6a8 0x183d6dc44 0x181640358 0x1816402d8 0x18163fb60 0x18163d738 0x18155e2d8 0x1833eff84 0x18ab0b880 0x1049993ac 0x18108256c) libc ++ abi.dylib:以NSException类型的未捕获异常终止
答案 0 :(得分:0)
我也有同样的问题,但是我使用下面的代码解决了:
override func viewDidLoad() {
super.viewDidLoad()
currencyPicker.delegate = self
currencyPicker.dataSource = self
}