我有一個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'數組?它是一個「科目」('[科目]')的數組? –