今天是一个特殊的日子(Mac pro 敲的 爽。。。 昨天到的)

//
// QRViewController.m// #import "QRViewController.h" @interface QRViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (weak, nonatomic) IBOutlet UILabel *fruitLable;//水果
@property (weak, nonatomic) IBOutlet UILabel *mainLabel;//主菜
@property (weak, nonatomic) IBOutlet UILabel *drinkLabel;//饮料
@property (nonatomic,strong) NSArray *foods;
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
- (IBAction)ranDom; @end @implementation QRViewController - (void)viewDidLoad {
[super viewDidLoad];
for (int i=; i<self.foods.count; i++) {
[self pickerView:nil didSelectRow: inComponent:i];
}
//[self pickerView:nil didSelectRow:0 inComponent:0];
//[self pickerView:nil didSelectRow:0 inComponent:1];
//[self pickerView:nil didSelectRow:0 inComponent:2];
}
/**
*懒加载数据
*/
- (NSArray *)foods
{
if(_foods==nil){
NSString *path=[[NSBundle mainBundle] pathForResource:@"foods" ofType:@"plist"];
NSArray *arraylist=[NSArray arrayWithContentsOfFile:path];
_foods=arraylist;
}
return _foods;
}
#pragma mark -数据源方法
/**
*一共多少列
*/
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return self.foods.count;
}
/**
* 某一列显示多少行
*/
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
NSArray *subfoods=self.foods[component];
return subfoods.count;
} #pragma mark - 代理方法
/**
*某一列中的某一行显示的数据
*/
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return self.foods[component][row];
}
/**
*选中某一行一列
*/
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if(component==){//水果
self.fruitLable.text=self.foods[component][row];
}else if(component==){//主菜
self.mainLabel.text=self.foods[component][row];
}else if(component==){//饮料
self.drinkLabel.text=self.foods[component][row];
}
}
/**
*随机生成一个
*/
- (IBAction)ranDom {
for (int i=; i<self.foods.count; i++) {
//每一行的总长度
int count=[self.foods[i] count];
//生成一个随机数
int row=arc4random()%count;
//设置pickerView选中的列的行
[self.pickerView selectRow:row inComponent:i animated:YES];
//设置Label的文字
[self pickerView:nil didSelectRow:row inComponent:i];
} } @end

ios中 pickerView的用法的更多相关文章

  1. iOS中block的用法 以及和函数用法的区别

    ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候  MyBlock(); 带参数的 ...

  2. ios 中pickerView用法之国旗选择

    QRViewController控制器 // // QRViewController.m // #import "QRViewController.h" #import " ...

  3. iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)

    1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...

  4. ios中图片拉伸用法

    - (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...

  5. iOS中的CocoaPods用法及常用命令

     CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...

  6. ios中Pldatabase的用法

    将PLDATABASE加入到工程 下载PLDatabase 的dmg文件 将PLDatabase的framework复制到工程根目录在工程中加入该framework使用该framework进行数据库操 ...

  7. iOS中NSScanner 的用法

    NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...

  8. IOS中NSUserDefaults的用法(轻量级本地数据存储)

    NSUserDefaults适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名.密码之类的,个人觉得使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefa ...

  9. IOS中TableView的用法

    一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...

随机推荐

  1. 微擎查询SQL语句常用

    pdo_fetch:根据SQL语句,查询一条记录 array | boolean pdo_fetch($sql, $params = array()); // :uid 是参数的一个点位符,没有使用引 ...

  2. 「THUWC 2017」在美妙的数学王国中畅游

    这个题目很明显在暗示你要用泰勒展开. 直接套上去泰勒展开的式子,精度的话保留12项左右即可. 分别维护每一项的和,可能比较难写吧. 然后强行套一个LCT就没了.

  3. Oracle 三大范式

    范式:数据库设计对数据的存储性能,还有开发人员对数据的操作都有莫大的关系.所以建立科学的,规范的的数据库是需要满足一些.规范的来优化数据数据存储方式.在关系型数据库中这些规范. 第一范式:数据库表中的 ...

  4. MongoDB\BSON\UTCDateTime::toDateTime

    示例# 1 MongoDB \ BSON \ UTCDatetime:toDateTime()例子 <?php $utcdatetime = new MongoDB\BSON\UTCDateTi ...

  5. 精通Oracle的关键是……(Ask Tom上最经常被问到的问题)(转)

    原文地址:http://www.ituring.com.cn/article/37548 这是我在asktom上最经常收到的问题:我需要怎么做才能变成一个专家呢?关于Oracle,有这样的一个关键事物 ...

  6. ORM框架之SQLALchemy

    一.面向对象应用场景: 1.函数有共同参数,解决参数不断重用: 2.模板(约束同一类事物的,属性和行为) 3.函数编程和面向对象区别: 面向对象:数据和逻辑组合在一起:函数编程:数据和逻辑不能组合在一 ...

  7. ActiveMQ Advisory Message

    http://activemq.apache.org/advisory-message.html ActiveMQ broker 内部维持了一些 topic,保存了一些系统信息,客户端可以订阅这些 t ...

  8. 把旧系统迁移到.Net Core 2.0 日记 (15) --Session 改用Redis

    安装Microsoft.Extensions.Caching.Redis.Core NuGet中搜索Microsoft.Extensions.Caching.Redis.Core并安装,此NuGet包 ...

  9. vsCode快捷键设置

    // 快捷键设置 keyiing.json // 将键绑定放入此文件中以覆盖默认值 [     /* // 转换大写     {         "key" : "ctr ...

  10. Win10系列:UWP界面布局基础5

    (2)编写后台代码访问资源 下面通过一个例子来演示如何编写后台代码引用资源.新建一个Windows应用商店的空白应用程序项目,将其命名为AccessResourceApplication,打开项目下的 ...