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. 网页分享到微博、QQ、QQ空间、微信

    <ul id="content-share-list" class="bdsharebuttonbox bdshare-button-style0-16" ...

  2. spring quartz执行两次问题

    解决quartz定时任务被触发两次的问题: 其中<Host/>告诉tomcat,在启动的时候加载webapps下的所有项目工程文件,<Context/>又让tomcat再加载了 ...

  3. 2019/3/28 wen 继承

  4. sliver

    import 'package:flutter/material.dart';import 'package:xxx/bloc/bloc.dart';import 'package:xxx/model ...

  5. Linux sar工具安装使用

    使用sar Sar是后台进程sadc的前端显示工具,安装名为“sysstat”的包后,sadc就会自动从内核收集报告并保存.   安装sar [root@localhost ~]# yum insta ...

  6. Linux cached过高问题

    1. cached主要负责缓存文件使用, 日志文件过大造成cached区内存增大把内存占用完 . Free中的buffer和cache:(它们都是占用内存):buffer : 作为buffer cac ...

  7. [c/c++] programming之路(17)、高级指针

    一.二级指针 二级指针的作用:1.函数改变外部变量指针2.外挂改变一个指针的值 #include<stdio.h> #include<stdlib.h> void main() ...

  8. markdown的css样式(自己写的)

    markdown的css样式,这些是我自己配置的,感觉可以的话你可以添加下,不适合自己的话可以仿照第二种自己写个比较好的css样式. 第一种 /* RESET ==================== ...

  9. Intellij IDEA的下载安装与破解

    一,下载与安装 1.官网下载:https://www.jetbrains.com/idea/ 2.选择Windows对应版本安装 二,破解 1.下载破解补丁:http://idea.lanyus.co ...

  10. Spring Boot 数据库连接池 Druid

    简介 数据库连接是一种关键的有限的昂贵的资源,这一点在多用户的网页应用程序中体现得尤为突出.对数据库连接的管理能显著影响到整个应用程序的伸缩性和健壮性,影响到程序的性能指标.数据库连接池正是针对这个问 ...