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 ...
随机推荐
- Git将本地项目上传到GitHub
本文转载于:https://segmentfault.com/a/1190000011909294 https://www.cnblogs.com/cxk1995/p/5800196.html 我们使 ...
- Python Microsoft Visual C++ 10.0 is required (Unable to find vcvarsall.bat)
在windows 平台下,当python使用以下方式安装时,可能出现以下错误: > python setup.py install error: Microsoft Visual C++ 10. ...
- NPM 使用及npm升级中问题解决
NPM是随同NodeJS一起安装的包管理工具,能解决NodeJS代码部署上的很多问题,常见的使用场景有以下几种: 允许用户从NPM服务器下载别人编写的第三方包到本地使用. 允许用户从NPM服务器下载并 ...
- sku 加减号的增删
---恢复内容开始--- //php页面public function test(){ $id="1"; $data=Db::table('week3_goods') ->j ...
- Java环境下shiro的测试-认证与授权
Java环境下shiro的测试 1.导入依赖的核心jar包 <dependency> <groupId>org.apache.shiro</groupId> < ...
- Linux中环境变量文件
一.环境变量文件介绍 转自:http://blog.csdn.net/cscmaker/article/details/7261921 Linux中环境变量包括系统级和用户级,系统级的环境变量是每个登 ...
- Eclipse集成weblogic教程
1.在线安装插件 1.1安装Oracle Weblogic Servers Tools oeop是添加的软件仓库的名字,随便写主要是方便记. 仓库链接:http://www.oracle.com/te ...
- CentOS查询系统版本
1.cat /proc/version 2.cat /etc/redhat-release 3.cat /proc/version 4.uname -a
- learning at command AT+CGSN
AT command AT+CGSN [Purpose] Learning how to get mobile module international Mobile Equipment ...
- WPF实现DoEvents
WPF实现DoEvents 原创 2011年06月30日 12:23:00 标签: wpf / object 2550 static void DoEvents() { DispatcherFrame ...