zoukankan      html  css  js  c++  java
  • UiPickerView基本使用方法

    注意:

    1.使用PickerView之前需要指定数据源对象和代理对象。

    2.需要使用到两个协议:UiPickerViewDataSource,数据源协议、   UiPickerViewDelegate代理协议

    一、UiPickerView显示数据的步骤

    1.懒加载Plist文件

    2.设置控制器是当前UiPickerView的数据源对象和代理对象

    3.实现数据源方法numberOfComponentsInPickerView返回列的个数

    4.实现数据源方法pickerView:numberOfRowsInComponent返回每列的行数

    5.实现代理方法pickerView:titleForRow:,返回每一行的数据内容

    6.监听UiPickerView的选择事件,将当前选中项显示到指定的label上

    二、主动设置UIPickerView选中某项

    调用UIPickerView的selectRow:inComponent:animated:方法设置某项被选中。

    注意: 当调用完毕selectRow:inComponent:animated:方法后, 系统并不会主动调用UIPickerView代理的- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component方法, 所以要想让Label发生变化, 必须手动调用该方法。

    三、UIPickerView的重新加载方法

    - (void)reloadAllComponents;

    - (void)reloadComponent:(NSInteger)component;

    上面两个方法表示重新刷新数据, 即: 重新调用数据源方法与代理方法。

    四、最后我要补充一点,生成随机数字

    arc4random()

    C语言函数

    随机生成一个无符号整数(0或所有正整数)

    随机生成一个 0 – n 之间的数字

    arc4random() % (n + 1)

    arc4random_uniform(12)

  • 相关阅读:
    设计模式开始--工厂模式
    设计模式开始--UML类之间关系表示
    设计模式开始1--不明觉厉
    Gas Station
    Validate Binary Search Tree
    Word Ladder
    (转)基于快速排序的TOPK算法
    Number of 1 Bits
    Word Search
    Rotate Array
  • 原文地址:https://www.cnblogs.com/xdios/p/4493258.html
Copyright © 2011-2022 走看看