UIPicker错误[__NSCFConstantString _isResizable] :?

时间:2012-07-30 21:40:09

标签: objective-c ios xcode uipickerview

UI Pickers让我再次陷入困境,我仍在学习UI选择器,所以不确定我是否在这里做了一些根本性的错误。

尝试从行UIPicker显示图像。

错误:

*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[__NSCFConstantString _isResizable]: unrecognized selector sent to instance 0x70fc' *** First throw call stack:

下面是代码:

#import "Imagepick.h"

@interface Imagepick ()

@end

@implementation Imagepick
 @synthesize select;
@synthesize imageview;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
    // Custom initialization
}
return self;
}

- (void)viewDidLoad
{


   ////arrays & objects
   arrStatus = [[NSArray alloc] initWithObjects:@"pic1",@"pic2",nil];




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

-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:   (NSInteger)component
 {

return arrStatus.count;


 }

-(NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row    forComponent:(NSInteger)component
 {

  return [arrStatus objectAtIndex:row];

 }
 - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component

{

 [imageview setImage:[arrStatus objectAtIndex:row]]; UIImage *pic1 = [[UIImage alloc]  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"appstorelogo" ofType:@"png"]];

  [imageview setImage:[arrStatus objectAtIndex:row]]; UIImage *pic2 = [[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"applogo" ofType:@"png"]];

 }



 - (void)viewDidUnload
{
[self setImageview:nil];
[self select:nil];
[super viewDidUnload];
// Release any retained subviews of the main view.
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

* pic1&的未使用变量警告pic2如果相关?

1 个答案:

答案 0 :(得分:7)

你的问题是[imageview setImage:[arrStatus objectAtIndex:row]];您正在尝试使用字符串setImage。

你也没有使用pic1和pic2。

您可能想要做的是将图像名设置为数组:

arrStatus = [[NSArray alloc] initWithObjects:@"appstorelogo",@"applogo",nil];

然后设置图像

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    UIImage *img = [[UIImage alloc]  initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:[arrStatus objectAtIndex:row] ofType:@"png"]];

    [imageview setImage:img]; 
}