iOS App中UIPickerView选择栏控件的使用实例解析

2020-01-15 14:28:19王旭

2、创建数据。我们用到的数据如下:

iOS,App,UIPickerView

在前边的文章中曾经提到过plist文件,现在,我们就要用plist文件存储以上数据。为此,选择File — New — New File,在打开的窗口中,左边选择iOS中的Resource,右边选择Property List:

iOS,App,UIPickerView

单击Next,在打开的窗口中,Save As中输入名称provinceCities,Group选择Supporting Files:

iOS,App,UIPickerView

单击Create,就创建了provinceCities.plist。然后往其中添加数据,如下图所示:

iOS,App,UIPickerView

3、单击ViewController.h,向其中添加代码:

复制代码
#import <UIKit/UIKit.h>

 

#define kProvinceComponent 0
#define kCityComponent 1

@interface ViewController : UIViewController <UIPickerViewDelegate, UIPickerViewDataSource>

@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@property (strong, nonatomic) NSDictionary *provinceCities;
@property (strong, nonatomic) NSArray *provinces;
@property (strong, nonatomic) NSArray *cities;

- (IBAction)buttonPressed;

@end


4、单击ViewController.m,向其中添加代码: