我有一个pickerView,其中有很多主题。每一个问题是这样的一类:无法选择pickerView的默认值
class subjects {
var idSubject: String = "";
var nameSubject: String = "";
var notesSubject: String = "";
var colorSubject: String = "";
init(subjectId: String, subjectName: String, subjectNotes: String, subjectColor: String) {
idSubject = subjectId
nameSubject = subjectName
notesSubject = subjectNotes
colorSubject = subjectColor
}
func printSubject(){
print(idSubject," - ",nameSubject," - ",notesSubject," - ",colorSubject)
}
}
设置我这样pickerView:
public func numberOfComponents(in pickerView: UIPickerView) -> Int{
return 1
}
public func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int{
return MenuViewController.subjectsArray.count
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
self.view.endEditing(true)
return MenuViewController.subjectsArray[row].nameSubject
}
我想选择一个特定主题的行,但我不能因为它indexOf
if let index = MenuViewController.subjectsArray.indexOf("Matematica") {
self.subjectsMenu.selectRow(index, inComponent: 0, animated: true)
}
有人可以帮助我:在这个代码行 - “无法将类型‘字符串’到预期的参数类型‘>布尔(学科)抛出’的价值”?
有什么类型'subjectsArray'数组?它是一个“科目”('[科目]')的数组? –