UIPickerView 不显示

发布于 2024-08-30 22:07:04 字数 745 浏览 4 评论 0原文

我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

英雄似剑 2024-09-06 22:07:04

如果未调用委托方法,则在 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;

我的痛♀有谁懂 2024-09-06 22:07:04

您尚未将委托分配给 UIPickerView,这就是没有调用任何委托方法的原因。

 UIPickerView *pickerView;
 pickerView.delegate = self;//write this line in view did load method.

希望这对您有帮助,如果这回答了您的问题,请告诉我..:)

you have not assigned the delegate to the UIPickerView thats the reason none of the delegate methods are called.

 UIPickerView *pickerView;
 pickerView.delegate = self;//write this line in view did load method.

Hope this helps and let me know if this answers your question..:)

等待圉鍢 2024-09-06 22:07:04

有时这是由于pickerview未连接到nib中的文件所有者的数据源和委托

sometimes it's due to the pickerview not being connected to the file Owner's datasource and delegate in the nib

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文