我有一个代码可以杀死我的应用程序这个例外“由于未捕获的异常终止应用程序'NSInvalidArgumentException',原因:' - [UIImage initWithImage:]:无法识别的选择器发送到实例0xd815930'”
- (void)viewDidLoad {
[super viewDidLoad];
[self addImageWithName:@"image10.jpg" atPosition:0];
for (int i=1; i< 11; i++) {
[self addImageWithName:[NSString stringWithFormat:@"image%i.jpg",i] atPosition:i];
}
[self addImageWithName:@"image1.jpg" atPosition:11];
scrollView.contentSize = CGSizeMake(1920, 416);
[scrollView scrollRectToVisible:CGRectMake(320, 0, 320, 416) animated:NO];
}
-(void)addImageWithName:(NSString *)imageString atPosition:(int)position{
UIImage *image = [UIImage imageNamed:imageString];
UIImageView *imageView = [[UIImage alloc] initWithImage:image];
imageView.frame = CGRectMake(position*320, 0, 320, 416);
[scrollView addSubview:imageView];
[imageView release];
}
我不知道我的错误在哪里
答案 0 :(得分:3)
UIImageView *imageView = [[UIImage alloc] initWithImage:image];
应该是
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
答案 1 :(得分:1)
UIImageView * imageView = [[ UIImageView alloc] initWithImage:image];
答案 2 :(得分:1)
这就是问题所在。
UIImageView *imageView = [[UIImage alloc] initWithImage:image];
将此替换为
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];