我的选择器视图未显示。我只看到一个空框,其中选择器视图应该是。我已完成以下所示的所有步骤。我的问题是,这是一个完整的清单还是我遗漏了什么?除非,我遗漏了一些东西,否则我将从头开始删除和重做,但认为列举所有步骤并确认它们应该足够是好的:
@property (weak, nonatomic) IBOutlet UIPickerView *pickerView;
4.在viewdidload中设置委托,虽然这对于pickerView.delegate = self;
5.订阅接口文件中的uipickerviewprotocol,如下所示:
@interface myVC : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource>
6.在实现文件中包含如下的委托方法,并指定要显示的数组
- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component{
return 10;
}
- (NSString *)pickerView:(UIPickerView *)pickerView
titleForRow:(NSInteger)row
forComponent:(NSInteger)component
{
NSArray* cities = @[@"Oslo", @"Berlin", @"Cupertino", @"Palo Alto", @"Menlo Park", @"Mountain View", @"San Jose", @"Los Altos", @"Woodside", @"Berlin", @"Berlin"];
return cities[row];
}
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
_selectedCity= ([cities objectAtIndex:row]);
}
修改
还有其他需要或应该是否足够?