Search code examples
objective-ciosxcodeuipickerview

Error on UIPicker [__NSCFConstantString _isResizable]:?


UI Pickers got me stuck again, Im still learning with the UI picker so not sure if ive done something fundamentally wrong here.

Trying to display an image from row UIPicker.

Error:

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

Heres the code:

#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

* unused variable warning for pic1 & pic2 if relevant?


Solution

  • Your problem is [imageview setImage:[arrStatus objectAtIndex:row]]; You are trying to setImage with strings.

    You are also not using pic1, and pic2.

    What you might want to do is set the imagenames as the array like:

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

    and then set the images like

    - (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]; 
    }