由于未捕获的异常而终止应用程序

发布于 2024-10-21 08:03:19 字数 999 浏览 5 评论 0原文

我有一个代码杀死了我的应用程序,并出现以下异常“由于未捕获的异常'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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

风尘浪孓 2024-10-28 08:03:19
UIImageView *imageView = [[UIImage alloc] initWithImage:image];

应该是

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
UIImageView *imageView = [[UIImage alloc] initWithImage:image];

should be

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
一江春梦 2024-10-28 08:03:19

这就是问题所在。

UIImageView *imageView = [[UIImage alloc] initWithImage:image];

将此替换为此

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];
抹茶夏天i‖ 2024-10-28 08:03:19

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

UIImageView *imageView = [[UIImageView alloc] initWithImage:image];

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文