//返回每个组件上的行数 -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component { if(component==0) { return 2; } else if(component==1) { if(com1==0) { return 4; } else if(com1==1) { return 3; } } else if(component==2) { if(com1==0) { switch (com2) { case 0: return 3; break; case 1: return 1; case 2: return 1; case 3: return 1; default: break; } }else if(com1==1) { switch (com2) { case 0: return 3; break; case 1: return 3; case 2: return 2; default: break; } } } } //返回组件数 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView { return 3; } //每一列中每一行的具体内容 - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component { if (component==0) { switch (row) { case 0: return @"VIP专供"; case 1: return @"VIP牧宝经典"; default: break; } } else if(component==1) { if(com1==0) { switch (row) { case 0: return @"手编垫"; case 1: return @"养生垫"; case 2: return @"四季垫"; case 3: return @"亚麻座垫"; default: break; } } else if(com1==1) { switch (row) { case 0: return @"手编垫"; case 1: return @"养生垫"; case 2: return @"四季垫"; default: break; } } } else if(component==2) { if(com1==0) { if(com2==0) { switch (row) { case 0: return @"MY1301"; case 1: return @"MY1302"; case 2: return @"MY1303"; default: break; } } return @" "; } if(com1==1) { if(com2==0) { switch (row) { case 0: return @"MY1305"; case 1: return @"MY1306"; case 2: return @"MY1315"; default: break; } } if(com2==1) { switch (row) { case 0: return @"MBJ1301"; case 1: return @"MBJ1302"; case 2: return @"MBJ1303"; default: break; } } if(com2==2) { switch (row) { case 0: return @"MSJ1301"; case 1: return @"MSJ1302"; default: break; } } } } } //返回组件的高度,如果这个方法未实现,选取器会自动调整到合适的高度 -(CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component { return 40; } //-(CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component //{ // if(component==0) // { // return 160; // } // return (m_picker.frame.size.width-160)/2; // //} //选中哪一列哪一行 -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component { if(component==0) { com1 = row; } else if(component==1) { com2=row; } [m_picker reloadAllComponents]; }