您的位置:首页 > 产品设计 > UI/UE

UIPickerView

2016-07-05 00:00 197 查看
摘要: UIPickerView拾取器的轮子数,行数,标题以及更新加载

UIPickerView

#import "ViewController.h"

@interface ViewController ()<UIPickerViewDelegate,UIPickerViewDataSource>

@end

@implementation ViewController

(void)viewDidLoad {
[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

//拾取器,UIPickerView
_pickerView.delegate=self;
_pickerView.dataSource=self;
// _array=@[@[@"Year",@"2016",@"2015",@"2014",@"2013",@"2012",@"2011",@"2010",@"2009",@"2008",@"2007"],@[@"Mounth",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12"],@[@"Day",@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8",@"9",@"10",@"11",@"12",@"13",@"14",@"15",@"16",@"17",@"18",@"19",@"20",@"21",@"22",@"23",@"24",@"25",@"26",@"27",@"28",@"29",@"30"]];
//_pickerView.backgroundColor=[UIColor grayColor];
//_pickerView.backgroundColor=[UIColor clearColor];
//_pickerView.alpha=0.5;

//

NSArray *arrayUn = [NSKeyedUnarchiver unarchiveObjectWithFile:[NSHomeDirectory() stringByAppendingPathComponent:@"/Users/feifanchengxuyuan/Desktop/city.plist"]];
NSLog(@"%@",arrayUn);

//提取文件
NSString *str=@"/Users/feifanchengxuyuan/Desktop/city.plist";
_arrayI=[NSArray arrayWithContentsOfFile:str];
_arrayII=_arrayI[0][@"cities"];

for (id obj in _arrayI)
{
NSLog(@"%@",obj);
}

}
//1,轮子数
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
//return _array.count;
return [_arrayI[0] count];
}
//2,轮子行数
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
//return [_array[component]count];
if (component==0)
{
return _arrayI.count;
}
else
{
return _arrayII.count;
}
}
//3,标题
-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
//return _array[component][row];
if (component==0)
{
return _arrayI [row][@"state"];
}
else
{
return _arrayII [row];
}
}
//4,更新
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
if (component==0)
{
_arrayII=_arrayI [row][@"cities"];
//加载
[pickerView reloadComponent:1];
}
}

@end
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息