zoukankan      html  css  js  c++  java
  • IOS 拾取器控件

      拾取器是个常用控件。

      在使用拾取器之前需要引用两个协议   <UIPickerViewDataSource,UIPickerViewDelegate>

          还需要连接  datesource & delegate  

      调用协议后,需要重写三个方法

      -(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView     这个方法返回拾取器的 个数。

      -(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component  这个方法返回任意一个拾取器的 数值串

        if(component==0)

          {

              return array_1.count;

          }

          else

          {

              return array_2.count;

          }

          -(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component    这个方法返回  任意一个数值串的个数

      

    if(component==0)

        {

            return array_1.count;

        }

        else

        {

            return array_2.count;

        }

    -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component  

    {

        if(component==0)

        {

            NSString *select=[self.array_1 objectAtIndex:row];

            self.array_2=[self.date objectForKey:select];

            [self.picker reloadComponent:1];     //reloadComponet 方法 可以重新刷新 拾取器

        }

    }

    拾取器的数据可以从 p li s t文件里取出

    选择数组 

    选择数组类型。

      NSBundle * bundle=[NSBundle mainBundle];//得到一个bundle;

        NSString * plistPath=[bundle pathForResource:@"List" ofType:@"plist"];//获取路径

        NSDictionary *dic=[[NSDictionary alloc ]initWithContentsOfFile: plistPath]; //通过路径获取到一个字典

        self.date=dic;

        NSArray *array=[self.date allKeys];  //获取所有键

        NSArray *sorted=[array sortedArrayUsingSelector:@selector(compare:)];

        self.array_1=sorted;

        NSString *select_1=[self.array_1 objectAtIndex:0];  //获取第一个字符段

        NSArray *col2=[self.date objectForKey:select_1];

        self.array_2=col2;

     把plist文件里的数据放到一个 字典里。然后通过字典给拾取器赋值。

  • 相关阅读:
    PAT (Basic Level) Practise 1013 数素数
    PAT (Basic Level) Practise 1014 福尔摩斯的约会
    codeforces 814B.An express train to reveries 解题报告
    KMP算法
    rsync工具
    codeforces 777C.Alyona and Spreadsheet 解题报告
    codeforces 798C.Mike and gcd problem 解题报告
    nginx + tomcat多实例
    MongoDB副本集
    指针的艺术(转载)
  • 原文地址:https://www.cnblogs.com/stuwan/p/4355623.html
Copyright © 2011-2022 走看看