UIPickerView 不显示
我在 UIView 上有一个 UIPickerView。我已经在 .h 文件中实现了它的协议,并在 .m 文件中实现了委托:
<UIPickerViewDataSource, UIPickerViewDelegate>
在 IB 中,我已将上面的内容连接到选择器,我也有一个 IBoutlet。这些方法如下所示:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [self.arr count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return @"test";
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//do something
}
有什么想法我缺少哪一部分来让选择器工作吗?
I have a UIPickerView on a UIView. I've implemented its protocol in the .h and delegates in the .m files:
<UIPickerViewDataSource, UIPickerViewDelegate>
In IB, I've connected the above to the picker, which I also have an IBoutlet for. The methods look like this:
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
return [self.arr count];
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
return @"test";
}
- (void)pickerView:(UIPickerView *)thePickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
//do something
}
Any ideas which piece I'm missing to get the picker working?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果未调用委托方法,则在 IB 中仔细检查选取器视图的委托和数据源出口是否已连接到文件的所有者。
在 .h 文件中,选择器视图插座应如下声明:
@property (nonatomic,retain) IBOutlet UIPickerView *pickerView;
If the delegate methods are not getting called, then in IB double check that the picker view's delegate and datasource outlets are connected to File's Owner.
In the .h file, the picker view outlet should be declared like this:
@property (nonatomic, retain) IBOutlet UIPickerView *pickerView;
您尚未将委托分配给 UIPickerView,这就是没有调用任何委托方法的原因。
希望这对您有帮助,如果这回答了您的问题,请告诉我..:)
you have not assigned the delegate to the UIPickerView thats the reason none of the delegate methods are called.
Hope this helps and let me know if this answers your question..:)
有时这是由于pickerview未连接到nib中的文件所有者的数据源和委托
sometimes it's due to the pickerview not being connected to the file Owner's datasource and delegate in the nib