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. C++的重载操作符(operator)介绍(转)

    本文主要介绍C++中的重载操作符(operator)的相关知识. 1. 概述 1.1 what operator 是C++的一个关键字,它和运算符(如=)一起使用,表示一个运算符重载函数,在理解时可将 ...

  2. 剑指offer(27)字符串的排列

    题目描述 输入一个字符串,按字典序打印出该字符串中字符的所有排列.例如输入字符串abc,则打印出由字符a,b,c所能排列出来的所有字符串abc,acb,bac,bca,cab和cba. 输入描述:输入 ...

  3. 在数据库级别还是在service层进行级联删除

    在数据库配置级联删除的话,父表删除子表也删除.但是应该将维护代码放在一处,不要在service上删除父表,而在数据库层面级联删除子表,应该都在service层上进行删除.

  4. Hadoop Streaming 使用及参数设置

    http://www.cnblogs.com/hopelee/p/7476145.html https://blog.csdn.net/djy37010/article/details/5505103 ...

  5. springboot热部署(二)——springboot热部署与发布

    一.实现的方式概述 注意以下的热部署方式在IDEA是默认没有打开自动编译的,手动编译需要快捷键(Ctrl+Shift+F9),自动编译的修改配置如下:(注意刷新不要太快,会有1-2秒延迟) File- ...

  6. 02.Vue基本代码

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. 最新案例铁血军事手机客户端(IOS & Android)

    <铁血军事>Android手机客户端由铁血网开发和运营,为网友提供铁血论坛和铁血读书两大产品.使用Android手机客户端,您不仅可以阅读到最新军事资讯,随时参与精彩话题讨论,还可以在线阅 ...

  8. HRBUST 1186 青蛙过河 (思路错了)

    在河上有一座独木桥,一只青蛙想沿着独木桥从河的一侧跳到另一侧.在桥上有一些石子,青蛙很讨厌踩在这些石子上.由于桥的长度和青蛙一次跳过的距离都是正整数,我们可以把独木桥上青蛙可能到达的点看成数轴上的一串 ...

  9. 更改ssh,ftp默认端口

    1.  更改ssh端口 放置升级openssh之后做此步骤 配置文件/etc/ssh/sshd_config 注释掉Subsystem      sftp    /usr/libexec/openss ...

  10. Ajax+Struts2用户注册功能实现

    详细请参考源码(Github):https://github.com/QQ3330447288/ajaxRegister 1.目录结构 2.截图 3.核心代码: register.jsp <sc ...