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 ...
随机推荐
- MyBatis中mybatis-generator代码生成的一般过程
MyBatis框架的使用,可以参考我的文章: https://blog.csdn.net/JayInnn/article/details/81746571(基于Mybatis实现一个查库的接口) ht ...
- Spring配置表友好性优化思路
Spring配置表需要尽量保证对程序员的友好性,一下提供一种优化思路. 中途未保存,心态炸了,只贴图了,fuuuuuuuuuuuuuck 第一种(最烂,最不友好):以Json的格式保存在配置表中,程序 ...
- centos7 mysql+MHA高可用安装
https://dzone.com/articles/consul-proxysql-and-mysql-ha?utm_medium=feed&utm_source=feedpress.me& ...
- hbase知识
HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统 HBASE的目标是存储并处理大型的数据,更具体来说是仅需使用普通的硬件配置,就能够处理由成千上万的行和列所组成的大型数据. HBASE ...
- leetcode-algorithms-13 Roman to Integer
leetcode-algorithms-13 Roman to Integer Roman numerals are represented by seven different symbols: I ...
- 安卓——AlertDialog多样按钮
在xml 设计页面添加标签 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmln ...
- 使用ajax请求接口,跨域后cookie无法设置,全局配置ajax;及使用axios跨域后cookie无法设置,全局配置axios
问题一: 使用ajax/axios跨域请求接口,后端放行了,能够正常获取数据,但是cookie设置不进去,后端登录session判断失效 ajax解决办法: //设置ajax属性 crossDomai ...
- 784. Letter Case Permutation C++字母大小写全排列
网址:https://leetcode.com/problems/letter-case-permutation/ basic backtracking class Solution { public ...
- html 中一些不常见的标签
标签 描述 <b> 定义粗体文本. <big> 定义大号字. <em> 定义着重文字. <i> 定义斜体字. <small> 定义小号字. ...
- Redis入门第一课
为什么需要NoSQL? 1High performance:web1.0不能点赞互动,web2.0可以互动,里面有很多高并发读写 2Huge Storage:海量数据的高效率存储和访问 3High ...