zoukankan      html  css  js  c++  java
  • 在一个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 }
  • 相关阅读:
    银行数据仓库体系实践(6)--调度系统
    银行数据仓库体系实践(5)--数据转换
    银行数据仓库体系实践(4)--数据抽取和加载
    银行数据仓库体系实践(3)--数据架构
    银行数据仓库体系实践(2)--系统架构
    银行数据仓库体系实践(1)--银行数据仓库简介
    敏捷开发和传统开发区别
    source ~/.bash_profile是什么意思
    oracle里的DBLINK是做什么的
    flex-direction的值及使用效果
  • 原文地址:https://www.cnblogs.com/dongweiq/p/3653503.html
Copyright © 2011-2022 走看看