zoukankan      html  css  js  c++  java
  • UIPickerView的使用

    DataSource协议

    必须要实现这两个方法

        // 返回pickerView有多少列
        - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
    {
        return self.foods.count;
    }
        // 返回第component列有多少行
        - (NSInteger)r :(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
    {
        return [self.foods[component] count];
    }

    Delegate协议

    常用的几种方法

    // 返回第component列的每一行的行高
    - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
    {
        return 80.0;
    }
    
    // 返回第component列第row行的标题
    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
    {
        return @"aaaaa";
    }
    
    // 返回第component列第row行的View
    - (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
    {
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 60, 60)];
    
        v.backgroundColor = [UIColor redColor];
    
        return v;
    }
    
    // 选中第component第row的时候调用
    // 注意:这个方法必须用户主动拖动pickerView,才会调用
    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        NSLog(@"%s---%ld-%ld",__func__,component,row);
    }
  • 相关阅读:
    2020.9.21
    企业应用架构模式003——对象-关系结构模式
    企业应用架构模式002
    企业应用架构模式001
    代码大全003/
    代码大全002/
    每日总结
    数论必刷题
    Tarjan求割点(割顶) 割边(桥)
    Luogu 2018 秋令营 Test 2
  • 原文地址:https://www.cnblogs.com/luoze/p/5468168.html
Copyright © 2011-2022 走看看