錯誤:錯誤:類型 'GearViewController' 不符合協議 'UIPickerViewDataSource'
Type 'GearViewController' does not conform to protocol 'UIPickerViewDataSource'
基於apple documentation只有2個用於UIPickerViewDataSource所需的方法。兩者都包含在下面的代碼中。我認爲語法是正確的。 (但可能不是)
類/控件聲明和init。 (很多其他的代碼爲清楚起見去除了全部代碼中如果需要的話,我將修改,只是試圖保持簡單。)
class GearViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UIPickerViewDataSource, UIPickerViewDelegate{
@IBOutlet weak var pickerGearCategory: UIPickerView!
override func viewDidLoad() {
super.viewDidLoad()
pickerGearCategory.dataSource = self
pickerGearCategory.delegate = self
}
委託和數據源
let gearCategoryPickerData = CategoryRepository.allCategories()
//MARK: CategoryPicker- Delegates and data sources
//MARK: CategoryPicker - Data Sources
//Required
func numberOfComponents(in pickerGearCategory: UIPickerView) -> Int {
return 1
}
//Required
func pickerGearCategory(pickerGearCategory: UIPickerView, numberOfRowsInComponent component: Int) -> Int {
return gearCategoryPickerData.count
}
func pickerGearCategory(pickerGearCategory: UIPickerView,titleForRow row: Int, forComponent component: Int) -> String? {
return gearCategoryPickerData[row].name
}
有語法錯誤,這個和下面兩個答案。想要'func pickerView(_:UIPickerView,numberOfRowsInComponent組件:Int) - > Int { return gearsCategoryPickerData.count }' –
符合變化,但需要驗證獲得預期結果,並且必須向真正的工作出發。 –
謝謝,這一改變就像一個魅力。更好的是,它指出了下一個帖子的另一個問題! –