ios中 pickerView的用法
今天是一个特殊的日子(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的用法的更多相关文章
- iOS中block的用法 以及和函数用法的区别
ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候 MyBlock(); 带参数的 ...
- ios 中pickerView用法之国旗选择
QRViewController控制器 // // QRViewController.m // #import "QRViewController.h" #import " ...
- iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)
1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...
- ios中图片拉伸用法
- (UIImage *)stretchableImageWithLeftCapWidth:(NSInteger)leftCapWidth topCapHeight:(NSInteger)topCap ...
- iOS中的CocoaPods用法及常用命令
CocoaPods是什么? ***CocoaPods的使用场景:*** 1. 当你开发iOS应用时,会经常使用到很多第三方开源类库,比如JSONKit,AFNetWorking等等.可能某个类库又用 ...
- ios中Pldatabase的用法
将PLDATABASE加入到工程 下载PLDatabase 的dmg文件 将PLDatabase的framework复制到工程根目录在工程中加入该framework使用该framework进行数据库操 ...
- iOS中NSScanner 的用法
NSScanner是一个类,用于在字符串中扫描指定的字符,尤其是把它们翻译/转换为数字和别的字符串.可以创建NSScanner时制定他的String属性,然后scanner会按照你的要求从头到尾扫描这 ...
- IOS中NSUserDefaults的用法(轻量级本地数据存储)
NSUserDefaults适合存储轻量级的本地数据,比如要保存一个登陆界面的数据,用户名.密码之类的,个人觉得使用NSUserDefaults是首选.下次再登陆的时候就可以直接从NSUserDefa ...
- IOS中TableView的用法
一.UITableView 1.数据展示的条件 1> UITableView的所有数据都是由数据源(dataSource)提供的,所以要想在UITableView展示数据,必须设置UITable ...
随机推荐
- linux搭建smb、挂载smb、Windows共享
实现Linux系统之间共享文件资源以及在Linux系统与Windows系统之间共享文件 Samba软件包的构成 服务端:samba 客户端:samba-client 公共组件:samba-common ...
- JS onclick事件获取空间value
1. HTML onclick = btnAction(this.value) 2. JS btnAction(v){ alert(v) }
- 【IDEA】【5】快捷键
前言: 1,更改快捷键:File->Settings->Keymap 2,我自定义的快捷键 shitf+alt+s getter,setter,toString方法 (修改处:Keymap ...
- CF-503div2-A/B/C
A. New Building for SIS time limit per test 1 second memory limit per test 256 megabytes input stand ...
- SecureCRT自动记录日志
From: http://lzj0470.iteye.com/blog/1189368 今天在推特上看到有人谈起SecureCRT日志记录的问题,貌似很多人都有这习惯 我是开始工作后才使用Secure ...
- AWR报告学习示例
1. 参数1 AAS AAS讲解 elapsed 为 该AWR性能报告的时间跨度 DB_TIME =所有前台session花费在database调用上的总和时间. 注意:前台进程 foregrou ...
- Leetcode 1021. 最佳观光组合
1021. 最佳观光组合 显示英文描述 我的提交返回竞赛 用户通过次数91 用户尝试次数246 通过次数92 提交次数619 题目难度Medium 给定正整数数组 A,A[i] 表示第 i 个观 ...
- Leetcode 1005. K 次取反后最大化的数组和
1005. K 次取反后最大化的数组和 显示英文描述 我的提交返回竞赛 用户通过次数377 用户尝试次数413 通过次数385 提交次数986 题目难度Easy 给定一个整数数组 A,我们只能用 ...
- python中几种循环体
条件判断与循环 1.条件判断 if <条件判断1>: <执行1> elif <条件判断2>: <执行2> elif <条件判断3>: < ...
- python爬虫---BeautifulSoup的用法
BeautifulSoup是一个灵活的网页解析库,不需要编写正则表达式即可提取有效信息. 推荐使用lxml作为解析器,因为效率更高. 在Python2.7.3之前的版本和Python3中3.2.2之前 ...