【发布时间】:2018-01-06 02:36:58
【问题描述】:
我有一个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 它“无法将'String'类型的值转换为预期的参数类型'(subjects) throws -> Bool'”代码行数:
if let index = MenuViewController.subjectsArray.indexOf("Matematica") {
self.subjectsMenu.selectRow(index, inComponent: 0, animated: true)
}
有人可以帮我吗?
【问题讨论】:
-
subjectsArray数组的类型是什么?是subjects([subjects]) 的数组吗?
标签: swift uipickerview