2012-07-30 19 views
1

用戶界面選擇器讓我再次陷入困境,我仍然在學習用戶界面選擇器,所以不確定是否在此做了一些根本性錯誤。UIPicker [__NSCFConstantString _isResizable]錯誤:?

嘗試顯示行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如果相關變量的警告?

回答

7

你的問題是[imageview setImage:[arrStatus objectAtIndex:row]];您正嘗試使用字符串設置圖像。

您還沒有使用圖片1和圖片2。

什麼,你可能想要做的是設置imagenames像數組:

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]; 
} 
+0

+1更準確的答案比我(刪除),爲OP的問題。 – justin 2012-07-30 22:34:03

+0

謝謝!!!!這就是整理它,以及一個不錯的解決方案。加一個給你,先生! – JSA986 2012-07-30 22:34:12