0

我有一个极客名称数组和每个极客职业的数组。极客名称应该出现在 UIPicker 中。选择名称后,选择器的底部应显示所选玩家的图像和职业。我无法将图像作为 _ImageView = @[@"....我收到以下消息:

2013-05-02 13:40:03.761 Assignment5[2968:c07] -[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7549d30
2013-05-02 13:40:03.780 Assignment5[2968:c07] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[UIView numberOfComponentsInPickerView:]: unrecognized selector sent to instance 0x7549d30'
*** First throw call stack:
(0x1c92012 0x10cfe7e 0x1d1d4bd 0x1c81bbc 0x1c8194e 0xc634 0xd25f 0x642dd 0x10e36b0 0x228efc0 0x228333c 0x228eeaf 0x1032bd 0x4bb56 0x4a66f 0x4a589 0x497e4 0x4961e 0x4a3d9 0x4d2d2 0xf799c 0x44574 0x4476f 0x44905 0x4d917 0x1196c 0x1294b 0x23cb5 0x24beb 0x16698 0x1beddf9 0x1bedad0 0x1c07bf5 0x1c07962 0x1c38bb6 0x1c37f44 0x1c37e1b 0x1217a 0x13ffc 0x1e9d 0x1dc5)
libc++abi.dylib: terminate called throwing an exception

这是我的代码:

视图控制器.h

#import <UIKit/UIKit.h>

@interface Assignment5ViewController : UIViewController
<UIPickerViewDelegate, UIPickerViewDataSource>
@property (strong, nonatomic) IBOutlet UIPickerView *picker;
@property (strong, nonatomic) IBOutlet UILabel *career;
@property (strong, nonatomic) IBOutlet UIImageView *geekImageView;

@property (strong, nonatomic)NSArray *geekNames;
@property (strong, nonatomic)NSArray *careerNames;

@end

视图控制器.m

@interface Assignment5ViewController ()

@end

@implementation Assignment5ViewController


- (void)viewDidLoad
{
    [super viewDidLoad];

    _geekNames = @[@"Alan Turing", @"Bill Gates", @"Dennis Ritchie", @"James Gosling", @"Larry Wall", @"Linus Torvalds", @"Mark Zuckerberg", @"Steve Jobs", @"Tim Berners-Lee", @"Vinton Cerf"];

    _careerNames = @[@"Conceived Turing Machine", @"Started Microsoft", @"Created C and Unix", @"Created Java Language", @"Created Perl Language", @"Created Linux OS", @"Created Facebook", @"Started Apple", @"Created World-Wide-Web", @"Created TCP/IP"];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)textFieldReturn:(id)sender
{
    [sender resignFirstResponder];
}

#pragma mark
#pragma mark PickerView DataSource

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

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
    return _geekNames.count;
}

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

#pragma mark -
#pragma mark PickerView Delegate

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component
{
    _careerNames = [[NSString alloc]initWithFormat:@"%@", [_geekNames objectAtIndex:row]];

}

@end
4

1 回答 1

0

从该错误看来,您已将选择器的数据源设置为 UIView 而不是您的视图控制器。你是如何设置数据源的?你是在IB做的吗?您应该删除该连接并重做。

于 2013-05-02T19:41:37.230 回答