• 在一个UIView中如何使用多个UIPickerView


    可以现在storyboard的UIView中拖入多个UIPickerView

    然后同样是继承相关的UIPickerView协议

    <UIPickerViewDataSource,UIPickerViewDelegate>

    接着重写相关方法,在里面加入if判断即可

    如下:

     1 - (void)viewDidLoad
     2 {
     3     [super viewDidLoad];
     4     
     5     _checkItemArray=[NSArray arrayWithObjects:@"十二导常规心电",@"test", nil];
     6     _applyArray=[NSArray arrayWithObjects:@"ECG",@"TEST", nil];
     7     _applyDocArray=[NSArray arrayWithObjects:@"工程师", @"test",nil];
     8     
     9     self.checkItemPicker.dataSource=self;
    10     self.applyPicker.dataSource=self;
    11     self.applyDocPicker.dataSource=self;
    12     
    13     self.checkItemPicker.delegate=self;
    14     self.applyPicker.delegate=self;
    15     self.applyDocPicker.delegate=self;
    16     
    17 }
    18 
    19 -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    20 {
    21     return 1;
    22 }
    23 
    24 -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    25 {
    26     if (pickerView==self.checkItemPicker)
    27     {
    28         return _checkItemArray.count;
    29     }
    30     else
    31         if (pickerView==self.applyPicker)
    32         {
    33             return _applyArray.count;
    34         }
    35         else
    36         {
    37             return _applyDocArray.count;
    38         }
    39 }
    40 
    41 -(UIView*)pickerView:(UIPickerView*)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    42 {
    43     UILabel *myView=nil;
    44     
    45     myView=[[UILabel alloc]initWithFrame:CGRectMake(0.0, 0.0, 264, 30)];
    46     myView.textAlignment=NSTextAlignmentRight;
    47     
    48     if (pickerView==self.checkItemPicker) {
    49         myView.text=[_checkItemArray objectAtIndex:row];
    50         
    51     }else if(pickerView==self.applyPicker){
    52         myView.text=[_applyArray objectAtIndex:row];
    53     }else{
    54         myView.text=[_applyDocArray objectAtIndex:row];
    55     }
    56     myView.font=[UIFont systemFontOfSize:17];
    57     myView.textColor=[UIColor blackColor];
    58     myView.backgroundColor=[UIColor clearColor];
    59     return  myView;
    60     
    61 }
  • 相关阅读:
    VIM 文本对象选择
    XLA优化实例
    TVM/Relay 的 PartitionGraph()(mod) 函数讨论整理
    OpenCL通用异构开放环境
    LLVM IR 理解
    vue——请求跨域时,vcli2/vcli3设置代理
    【转】SQL 21天实战练习
    bash命令
    linux命令
    jenkins技术
  • 原文地址:https://www.cnblogs.com/dongweiq/p/3653503.html
Copyright © 2020-2023  润新知