【发布时间】:2016-01-14 10:39:47
【问题描述】:
相当新,我需要了解 UIPickerViews。
我以编程方式为我的项目创建了一个 UIPickerView:
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 375, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
[self.view addSubview:myPickerView];
}
然后添加了行数的方法:
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger numRows = 5;
return numRows;
}
按预期返回五个问号。然后我可以继续创建一个数组来填充这些行等......但接下来我会添加另一个 UIPickerView,如下所示:
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIPickerView *myPickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 200, 375, 200)];
myPickerView.delegate = self;
myPickerView.showsSelectionIndicator = YES;
[self.view addSubview:myPickerView];
UIPickerView *my2PickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 400, 375, 200)];
my2PickerView.delegate = self;
my2PickerView.showsSelectionIndicator = YES;
[self.view addSubview:my2PickerView];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger numRows = 5;
return numRows;
}
现在我有两个pickerview 控制器,它们都有五行。我的问题是如何选择该方法适用于哪个pickerview,还有谁能解释为什么该方法适用于项目中的所有pickerview?谢谢。
【问题讨论】: