Terminating app due to uncaught exception
I have a code that kill's my app with this exception "Terminating app due to uncaught exception 'NSInvalidArgumentExcep开发者_StackOverflow中文版tion', reason: '-[UIImage initWithImage:]: unrecognized selector sent to instance 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];
}
and I dont know where my mistake is
UIImageView *imageView = [[UIImage alloc] initWithImage:image];
should be
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
This is the problem.
UIImageView *imageView = [[UIImage alloc] initWithImage:image];
Replace this with this
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
精彩评论