xcode UIPickerView 的问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6692784/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 21:29:00  来源:igfitidea点击:

Trouble with UIPickerView

iphonexcodeuipickerviewuipickerviewcontroller

提问by Th3noon

I'm totally stuck with the UIPickerView. I keep getting the error :

我完全被 UIPickerView 困住了。我不断收到错误:

GDB: received signal: "SIGABRT".

GDB:接收信号:“SIGABRT”。

2011-07-14 13:35:19.132 MeldStad[677:207] *Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0xaac34c0'

2011-07-14 13:35:19.132 MeldStad[677:207] *由于未捕获的异常“NSInvalidArgumentException”而终止应用程序,原因:“-[UIView numberOfComponentsInPickerView:]:无法识别的选择器发送到实例 0xaac34c0”

I've read some solution on internet but none of them worked for me.. I've also tried more than 1 PickerView tutorial. Don't know what to do know.

我已经在互联网上阅读了一些解决方案,但没有一个对我有用..我还尝试了 1 个以上的 PickerView 教程。不知道该怎么办才知道。

Here is the source of the picker methods:

以下是选择器方法的来源:

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
    return 1;
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return [pickerData count];
}

- (NSString *)pickerView:
(UIPickerView *)pickerView titleForRow:
(NSInteger)row forComponent:(NSInteger)component
{
    return [pickerData objectAtIndex:row];
}

回答by Cyprian

The error is saying that you setup your UIPicker delegate in the IB to the UIView where you don't have UIPickerDelegate methods

错误是说您在 IB 中将 UIPicker 委托设置为没有 UIPickerDelegate 方法的 UIView

@interface YourViewController : UIViewController <UIPickerViewDelegate> 

Or you assigned your delegates to a wrong file. Check IB connection settings. Your datasource and delegate should be set to FilesOwner

或者您将代表分配给了错误的文件。检查 IB 连接设置。您的数据源和委托应设置为 FilesOwner