gpt4 book ai didi

objective-c - UIPicker [__NSCFConstantString _isResizable]错误:?

转载 作者:行者123 更新时间:2023-12-01 17:33:39 25 4
gpt4 key购买 nike

UI Pickers让我再次陷入困境,我仍在学习UI Picker,因此不确定ive是否在这里做了根本上的错误。

尝试显示来自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

*未使用的 pic1pic2变量警告是否相关?

最佳答案

您的问题是[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];
}

关于objective-c - UIPicker [__NSCFConstantString _isResizable]错误:?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11730051/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com