UIPickerView
作者:
哔哩哔哩智能喵 | 来源:发表于
2016-09-30 16:47 被阅读11次//控制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
本文链接:https://www.haomeiwen.com/subject/wbtryttx.html
网友评论