ios 中pickerView用法之国旗选择

QRViewController控制器
//
// QRViewController.m
//
#import "QRViewController.h"
#import "QRFlag.h"
#import "QRFlagView.h" @interface QRViewController ()<UIPickerViewDataSource,UIPickerViewDelegate>
@property (nonatomic,strong) NSArray *flags;
@end @implementation QRViewController - (void)viewDidLoad {
[super viewDidLoad];
}
/**
*懒加载国旗数据
*/
- (NSArray *)flags
{
if(_flags==nil){
NSString *path=[[NSBundle mainBundle] pathForResource:@"flags" ofType:@"plist"];
NSArray *arrayList=[NSArray arrayWithContentsOfFile:path];
NSMutableArray *dictArray=[NSMutableArray array];
for (NSDictionary *dict in arrayList) {
QRFlag *flag=[QRFlag flagWithDict:dict];
[dictArray addObject:flag];
}
_flags=dictArray;
}
return _flags;
}
#pragma mark - 设置数据源
/**
*设置列数
*/
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return ;
}
/**
*设置某一列的行
*/
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
return self.flags.count;
}
/**
*设置某一列中的某一行的显示数据
*/
//- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
//{
// QRFlag *flag=self.flags[row];
// return flag.name;
//} /**
* 第component列的第row行显示怎样的view
* 每当有一行内容出现在视野范围内,就会调用(调用频率高)
*/
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
{
QRFlagView *flagView=[QRFlagView flagViewWithResuingView:view];
flagView.flag=self.flags[row];
return flagView;
} - (CGFloat)pickerView:(UIPickerView *)pickerView rowHeightForComponent:(NSInteger)component
{
return [QRFlagView flogViewHeight];
} @end
QRFlag模型类
#import <Foundation/Foundation.h> @interface QRFlag : NSObject
@property (nonatomic,copy) NSString *name;
@property (nonatomic,copy) NSString *icon;
+(instancetype)flagWithDict:(NSDictionary *)dict;
- (instancetype)initWithDict:(NSDictionary *)dict;
@end //=================== #import "QRFlag.h" @implementation QRFlag
+(instancetype)flagWithDict:(NSDictionary *)dict
{
return [[self alloc] initWithDict:dict];
}
- (instancetype)initWithDict:(NSDictionary *)dict
{
if(self=[super init]){
[self setValuesForKeysWithDictionary:dict];
}
return self;
}
@end
XIB控制器
#import <UIKit/UIKit.h> @class QRFlag; @interface QRFlagView : UIView
@property (nonatomic,strong) QRFlag *flag; + (instancetype)flagViewWithResuingView:(UIView *)resuingView;
+(CGFloat)flogViewHeight;
@end //================= #import "QRFlagView.h"
#import "QRFlag.h" @interface QRFlagView()
@property (weak, nonatomic) IBOutlet UILabel *name;
@property (weak, nonatomic) IBOutlet UIImageView *icon;
@end @implementation QRFlagView + (instancetype)flagViewWithResuingView:(UIView *)resuingView
{
if(resuingView==nil)
{
NSBundle *bundle=[NSBundle mainBundle];
NSArray *obj=[bundle loadNibNamed:@"QRFlag" owner:nil options:nil];
return [obj lastObject];
}else{
return (QRFlag *)resuingView;
}
}
+(CGFloat)flogViewHeight
{
return ;
}
-(void)setFlag:(QRFlag *)flag
{
self.name.text=flag.name;
self.icon.image=[UIImage imageNamed:flag.icon];
} @end
ios 中pickerView用法之国旗选择的更多相关文章
- ios中 pickerView的用法
今天是一个特殊的日子(Mac pro 敲的 爽... 昨天到的) // // QRViewController.m// #import "QRViewController.h" @ ...
- ios 中pickerView城市选择和UIDatePicker生日选择
代码详见压缩包
- ios中MKHorizMenu用法
下载地址 https://github.com/MugunthKumar/MKHorizMenuDemo直接 加入MKHorizMenu目录即可 下载包地址 http://pan.baidu.com/ ...
- ios 中手势用法
pan拖动手势 - (void)viewDidLoad { [super viewDidLoad]; [self Pan]; // Do any additional setup after load ...
- 【IOS】ios中NSUserDefault与android中的SharedPreference用法简单对比
以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3405308.html 有Android开发经验的朋友对Shar ...
- iOS中block的用法 以及和函数用法的区别
ios中block的用法和函数的用法大致相同 但是block的用法的灵活性更高: 不带参数的block: void ^(MyBlock)() = ^{}; 调用的时候 MyBlock(); 带参数的 ...
- IOS第11天(2:UIPickerView自定义国旗选择)
国旗选择 #import "HMViewController.h" #import "HMFlag.h" #import "HMFlagView.h& ...
- iOS中Block的用法,举例,解析与底层原理(这可能是最详细的Block解析)
1. 前言 Block:带有自动变量(局部变量)的匿名函数.它是C语言的扩充功能.之所以是拓展,是因为C语言不允许存在这样匿名函数. 1.1 匿名函数 匿名函数是指不带函数名称函数.C语言中,函数是怎 ...
- iOS中UIPickerView常见属性和方法的总结
UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...
随机推荐
- 自制电脑usb红外遥控键盘
2010-08-08 19:20:00 看个ppt,还要一直按键盘或鼠标,能不能拿个遥控器控制一下. 动动脑,自己做一个吧. 电路分2部分,遥控器为发射部分,单片机为解码部分并且包含usb键盘功能. ...
- daily start
2019/4/26 1. to summerize the merge experience, about makefile, about compile error analysis. 2. loo ...
- Codeforces 438E The Child and Binary Tree - 生成函数 - 多项式
题目传送门 传送点I 传送点II 传送点III 题目大意 每个点的权值$c\in {c_{1}, c_{2}, \cdots, c_{n}}$,问对于每个$1\leqslant s\leqslant ...
- Codeforces 979E Kuro and Topological Parity - 动态规划 - 组合数学
题目传送门 传送点 题目大意 给定$n$个标号依次为$1, 2, \cdots, n$的点,其中一些点被染成一些颜色,剩下的点没有染色.你需要添加一些有向边并将剩下的点染色,满足有向边从编号小的一端指 ...
- 使用js方法时,调用的方法名明明一致,但就是不管用,解决
前提:代码全部写对 问题:调用的方法名明明一致,但就是不管用 举例:写了个function delete(){}方法, 点击调用delete方法,onclik="delete()" ...
- topcoder srm 595 div1
problem1 link 判断最后剩下哪些区间没有被其他区间覆盖. problem2 link 假设$b$的位置固定,那么不同的$a$会使得$[a,b]$有两种情况,第一种,$[a,b]$ is n ...
- HBase scan setBatch和setCaching的区别
HBase的查询实现只提供两种方式: 1.按指定RowKey获取唯一一条记录,get方法(org.apache.hadoop.hbase.client.Get) 2.按指定的条件获取一批记录,scan ...
- Linux下调试.Net core(1):lldb的安装
windows下,我们对于.net程序发生Crash,资源泄露,死锁等问题的分析,有神器windbg,那现在我们的.net core程序运行在linux上时,该怎么进行对对Core Dump文件进行分 ...
- python版 mapreduce 矩阵相乘
参考张老师的mapreduce 矩阵相乘. 转载请注明:来自chybot的学习笔记http://i.cnblogs.com/EditPosts.aspx?postid=4541939 下面是我用pyt ...
- Spring-AOP环绕监听出错
Exception in thread "main" org.springframework.aop.AopInvocationException: Null return val ...