Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/iphone/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 从UIPicker进行选择时尝试显示图像和标签_Iphone_Objective C_Ios6_Uipickerview - Fatal编程技术网

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

Iphone 从UIPicker进行选择时尝试显示图像和标签,iphone,objective-c,ios6,uipickerview,Iphone,Objective C,Ios6,Uipickerview,我有一个记录极客姓名的数组,还有一个记录每个极客职业生涯的数组。极客的名字应该出现在UIPicker中。选择姓名后,所选球员的形象和职业生涯应显示在选择器底部。我无法将图像以_ImageView=@[@“…的形式放置在数组中,因为每次尝试时,我的屏幕都会变黑。当我删除它时,它会运行,但当它在我的设备上打开后立即崩溃,我收到以下消息: 2013-05-02 13:40:03.761 Assignment5[2968:c07] -[UIView numberOfComponentsInPickerV

我有一个记录极客姓名的数组,还有一个记录每个极客职业生涯的数组。极客的名字应该出现在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

从那个错误看来,您将选取器的数据源设置为UIView而不是视图控制器。您是如何设置数据源的?您是在IB中设置的吗?您应该删除该连接并重新创建它。

我该怎么做?很抱歉,我以前从未这样做过,我非常困惑。我从未在目标c中编码过o我正在努力理解它。@user1787078,你怎么做什么?删除连接并重做它?你首先建立了连接吗?你怎么做到的?是的,但我遵循了一本书。仍然在努力掌握它。@user1787078,如果你右键单击(或控制单击)在IB中的picker视图上,它将显示一个黑色窗口,显示所有连接。它在“数据源”的右侧显示了什么?是的,我同时选择了数据源和代理。当我这样做并运行它时,我得到了一个黑框。好的,我想我现在知道你在说什么了。我将尝试一下。谢谢!
@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