由于未捕获的异常而终止应用程序
我有一个代码杀死了我的应用程序,并出现以下异常“由于未捕获的异常'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];
}
,我不知道我的错误在哪里
I have a code that kill's my app with this exception "Terminating app due to uncaught exception 'NSInvalidArgumentException', 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
应该是
should be
这就是问题所在。
将此替换为此
This is the problem.
Replace this with this
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];