zoukankan      html  css  js  c++  java
  • iOS之自定义pickerview(行驶里程数)

     1 #pragma mark -- 里程数按钮的点击事件
     2 
     3 - (void)mileageBtnClicked:(UIButton *)sender {
     4 
     5     UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"里程数/km
    
    
    
    
    
    
    
    " message:nil preferredStyle:UIAlertControllerStyleAlert];
     6 
     7     UIPickerView *mileage = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 40, 270, 150)];
     8 
     9     //指定Delegate
    10 
    11     mileage.delegate = self;
    12 
    13     //显示选中框
    14 
    15     mileage.showsSelectionIndicator = YES;
    16 
    17     [alert.view addSubview:mileage];
    18 
    19     
    20 
    21     UIAlertAction *ok = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    22 
    23         NSInteger row = [mileage selectedRowInComponent:0];
    24 
    25         NSString *mileageNum = [pickerData objectAtIndex:row];
    26 
    27         mileageLabel.text = [NSString stringWithFormat:@"%@km", mileageNum];
    28 
    29     }];
    30 
    31     
    32 
    33     UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action) {
    34 
    35     }];
    36 
    37     
    38 
    39     [alert addAction:ok];
    40 
    41     [alert addAction:cancel];
    42 
    43     [self presentViewController:alert animated:YES completion:^{ }];
    44 
    45     
    46 
    47     pickerData = [[NSArray alloc] initWithObjects:@"3000",@"3500",@"8000",@"8500",@"13000",@"13500",@"18000",@"18500",@"23000",@"23500",@"28500",@"33000",@"33500",@"38000",@"38500",@"43000",@"43500",@"48000",@"48500",@"53000",@"53500",@"58000",@"58500", nil];
    48 
    49 }
    50 
    51  #pragma mark -- UIPickerViewDataSource
    52 
    53 //返回显示的列数
    54 
    55 - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    56 
    57     return 1;
    58 
    59 }
    60 
    61 //返回显示的行数
    62 
    63 - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    64 
    65     return pickerData.count;
    66 
    67 }
    68 
    69 #pragma mark -- UIPickerViewDelegate
    70 
    71 //返回当前行的内容
    72 
    73 - (nullable NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component __TVOS_PROHIBITED {
    74 
    75     return [pickerData objectAtIndex:row];
    76 
    77 }
    78 
    79  
  • 相关阅读:
    (C/C++学习)6.数组指针和指针数组
    (C/C++学习)5.C++中的虚继承-虚函数-多态解析
    (C/C++学习)4.C++类中的虚函数表Virtual Table
    (C/C++学习)3.C++中cin的成员函数(cin.get();cin.getine()……)
    (C/C++学习)2.C语言中文件流操作基本函数总结
    关于for,while与do while
    计算机算法-C语言-统计字母数字个数解
    计算书费
    Truncate table
    sqlserver 在脚本中,为所有字符前没有N标记的字符增加N
  • 原文地址:https://www.cnblogs.com/rglmuselily/p/5216821.html
Copyright © 2011-2022 走看看