UIPickView:
1.遵守協(xié)議:
UIPickerViewDataSource, UIPickerViewDelegate
實現(xiàn)方法:
代理方法:
選中 行
- (void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
返回每一行顯示的內(nèi)容(返回的是字符串)
:給定選中組數(shù)據(jù),返回相應行數(shù)據(jù)
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
數(shù)據(jù)源方法
返回NSInteger類型
多少組
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
//code
}
每一組多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{
//code
};
這兩個方法返回具體NSInteger 為多少是根據(jù)具體你拿到的數(shù)據(jù),也就是plist文件里面 ---再設置
上面基本實現(xiàn)了,滾動獲得相應的數(shù)據(jù)
2.下面進行:選中每一行l(wèi)abel 相應得到哪一行的數(shù)據(jù)
通過label 中的數(shù)據(jù)從代理方法中判斷得到:
1.獲取選中的數(shù)據(jù)
NSString *selFood = self.foods[component][row];
2.設置給label
if (component == 0) {
self.fruitLbl.text = selFood;
} else if (component == 1) {
self.mainFoodLbl.text = selFood;
} else {
self.drinkLbl.text = selFood;
}