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用法之国旗选择的更多相关文章

  1. ios中 pickerView的用法

    今天是一个特殊的日子(Mac pro 敲的 爽... 昨天到的) // // QRViewController.m// #import "QRViewController.h" @ ...

  2. ios 中pickerView城市选择和UIDatePicker生日选择

    代码详见压缩包

  3. ios中MKHorizMenu用法

    下载地址 https://github.com/MugunthKumar/MKHorizMenuDemo直接 加入MKHorizMenu目录即可 下载包地址 http://pan.baidu.com/ ...

  4. ios 中手势用法

    pan拖动手势 - (void)viewDidLoad { [super viewDidLoad]; [self Pan]; // Do any additional setup after load ...

  5. 【IOS】ios中NSUserDefault与android中的SharedPreference用法简单对比

    以下内容为原创,欢迎转载,转载请注明 来自天天博客:http://www.cnblogs.com/tiantianbyconan/p/3405308.html 有Android开发经验的朋友对Shar ...

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

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

  7. IOS第11天(2:UIPickerView自定义国旗选择)

    国旗选择 #import "HMViewController.h" #import "HMFlag.h" #import "HMFlagView.h& ...

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

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

  9. iOS中UIPickerView常见属性和方法的总结

    UIPickerView是iOS中的原生选择器控件,使用方便,用法简单,效果漂亮. @property(nonatomic,assign) id<UIPickerViewDataSource&g ...

随机推荐

  1. IP通信基础学习第三周(上)

    TCP的连接情况有:同时打开,同时关闭,拒绝连接,异常终止连接. TCP流量控制的折中方法是滑动窗口协议,且TCP标准强烈不赞成发送窗口沿向后缩回. 在滑动窗口中,当A发送了11个字节的数据时,P3- ...

  2. k-means算法 - 数据挖掘算法(5)

    (2017-05-02 银河统计) k-means算法,也被称为k-平均或k-均值,是数据挖掘技术中一种广泛使用的聚类算法. 它是将各个聚类子集内的所有数据样本的均值作为该聚类的代表点,算法的主要思想 ...

  3. 各种数据库连接字符串 -- c#

    sqlite : connectionString="Data Source=|DataDirectory|\databasename.db;Pooling=true;FailIfMissi ...

  4. 一些sql优化原则

    1.我们在设计表的时候,尽量让字段拥有默认值,尽量不要让字段的值为null. 因为,在 where 子句中对字段进行 null 值判断(is null或is not null)将导致引擎放弃使用索引而 ...

  5. 常见的python的unittest用法

    python的unittest好处是通过python脚本编写用例,每个用例可以单独调试初始化和清理动作,因为都是用例都是代码所以调试起来也很方便:它的缺点是得先学会python,难易程度见仁见智吧,对 ...

  6. CSS hover

    CSS hover hover 鼠标移动到当前标签上时,以下css属性才能生效 <!DOCTYPE html> <html lang="en"> <h ...

  7. Python 事件驱动了解

    事件驱动 gevent协程可实现自动切换,协程在遇到IO时会进行切换,到另外一个请求,那协程是如何得知在什么时候在切换回去呢?   通常,我们写服务器处理模型的程序时,有以下几种模型: (1)每收到一 ...

  8. resmgr:cpu quantum 等待事件 top 1

    早上看昨天现场的报告,发现晚上七八点,resmgr:cpu quantum 等待事件排在i第一位,如下: 该事件是和资源管理相关的,如果启用资源管理计划,就可能遇到这个问题. 所以常规的解决方案是禁用 ...

  9. 内置函数filter()和匿名函数lambda解析

    一.内置函数filter filter()函数是 Python 内置的一个高阶函数,filter()函数接收一个函数 f 和一个list,这个函数 f 的作用是对每个元素进行判断,返回由符合条件迭代器 ...

  10. Servlet跳转到JSP页面后的路径问题相关解释

    一.现象与概念 1. 问题 在Servlet转发到JSP页面时,此时浏览器地址栏上显示的是Servlet的路径,而若JSP页面的超链接还是相对于该JSP页面的地址且该Servlet和该JSP页面不在同 ...