尝试从UIPicker中进行选择时显示图像和标签

时间:2013-05-02 18:17:29

标签: iphone objective-c ios6 uipickerview

请和我一起露面。我是新来的。

我有一个极客名字的数组和每个极客的职业生涯的数组。极客名称应出现在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

这是我的代码:

ViewController.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

ViewController.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

1 个答案:

答案 0 :(得分:0)

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