Ios Can';t将pickerView titleForRow设置为(字符串?,字符串?)
我使用的是CoreData,我试图在我的Ios Can';t将pickerView titleForRow设置为(字符串?,字符串?),ios,swift,core-data,uipickerview,ios10,Ios,Swift,Core Data,Uipickerview,Ios10,我使用的是CoreData,我试图在我的UIPickerView中有两个不同的列,其中包含存储和项目类型 当我运行它时,项目是“存在”的,但它们显示为“?” 这是我的titleForRow函数的代码: func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> (String?, String?) { //title let stor
UIPickerView
中有两个不同的列,其中包含存储和项目类型
当我运行它时,项目是“存在”的,但它们显示为“?”
这是我的titleForRow
函数的代码:
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> (String?, String?) {
//title
let store = stores[row]
let itemType = itemTypes[row]
// select store out of array of stores
return (store.name, itemType.type)
}
需要注意的是,Xcode给了我一个警告:
实例方法“pickerVIew(titleForRow:forComponent:)”几乎匹配
可选要求“pickerView(titleForRow:forComponent:)”的
协议UIPickerView
只能返回
String
type,不能返回tuple。如果要添加两列,则需要设置
pickerView.numberOfComponents = 2
并检查组件
参数,如:
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return component == 0 ? stores[row].name : itemTypes[row].type
}
作品非常感谢