2016-12-01 28 views
0

我有在我的PickerView位OG麻煩。首先我ViewController不接受UIPickerViewDataSource不管我做什麼。其次,PickerView將只顯示第一行。我需要它來顯示一個文本字段行和顯示器被稱爲學校PickerView - 視圖控制器不符合協議UIPickerViewDataSource

我該怎麼辦錯了?????

誰能幫助我,我發瘋

enter code here 
    private let typeComponent = 0 
    private let areaComponent = 1 
    private let typeOption = ["HighSchool of", "College of", "University of"] 
    private let areaOption = ["Miami", "Los Angeles", "New York"] 

     // PickerView - School 2 af 5 
    func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int { 
     return 2 
    } 
    // PickerView - School 3 af 5 
    func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { 
     if component == typeComponent { 
      return typeOption.count 
     } else { 
      return areaOption.count 
    } 
    } 
    // PickerView - School 4 af 5 
    func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { 
     if component == typeComponent { 
      return typeOption[row] 
     } else { 
     return areaOption[row] 

    } 
    } 
    // PickerView - School 5 af 5 
    func pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int) { 
//  school.text = pickOption[component][row] 

     let typeRow = pickerView.selectedRow(inComponent: (0)) 
     let areaRow = pickerView.selectedRow(inComponent: (1)) 
     let type = typeOption[typeRow] 
     let area = areaOption[areaRow] 
     school.text = "\(type)\(area)" 
    } 


    override func viewDidLoad() { 
     super.viewDidLoad() 



     //Placeholder TextView Interest and about 1 ag 3 
     Interest.delegate = self 
     Interest.text = "What are your interests..." 
     Interest.textColor = UIColor.lightGray 

     about.delegate = self 
     about.text = "Tell about yourself..." 
     about.textColor = UIColor.lightGray 

     //PickerView School 1 af 5 
     let pickerView = UIPickerView() 
     pickerView.delegate = self 
     pickerView.dataSource = self 
     pickerView.backgroundColor = UIColor.white 
     school.inputView = pickerView 

回答

1

實施的UIPickerViewDataSource所有需要的方法之前。如果你不符合UIPickerViewDataSource它會給你錯誤。這是需要

方法在你符合的類

以實現雨燕2.0

func numberOfComponentsInPickerView(pickerView: UIPickerView) -> Int 
func pickerView(pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int 

雨燕3.0

func numberOfComponents(in pickerView: UIPickerView) -> Int 
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int 
+0

由於它的工作:-) –

+1

很高興聽到:)接受的答案,因此會爲別人的幫助。 – Sahil

0

確保你的類符合UIPickerViewDataSource協議像這樣:

class YourViewController: UIPickerViewDataSource { 
// 
} 

更新時間:

對於斯威夫特3,你必須使用此數據源功能:

func numberOfComponents(in pickerView: UIPickerView) -> Int{ 
} 

而不是你所使用的。

+0

正如我寫的,在視圖控制器沒有您使用的斯威夫特3符合協議UIPickerViewDataSource –

+0

? –

+0

是我使用的斯威夫特3 –

相關問題