UIPickerView

//控制PickerView有多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return self.foods.count;
}
//控制PickerView的component列有多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [self.foods[component] count];
}
//控制PickerView的component列第row行的标题
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return self.foods[component][row];

}
//控制PickerView的component列的高度
-(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
    return 50;
}
// 选中第component列第row行的时候调用
// 注意:这个方法必须用户主动拖动pickerView,才会调用
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    NSLog(@"%ld----%ld",component,row);
    
    switch (component) {
        case 0:
            self.shuiguoLabel.text = self.foods[component][row];
            break;
        case 1:
           self.chaocaiLabel.text  = self.foods[component][row];
            break;
        case 2:
            self.yinliaoLabel.text  = self.foods[component][row];
            break;
        
    }
}

demo https://github.com/liuxingchen930831/UI-13UIPickerView

你可能感兴趣的:(UIPickerView)