gpt4 book ai didi

ios - NSArrayM insertObject :atindex 异常

转载 作者:行者123 更新时间:2023-11-28 18:30:58 28 4
gpt4 key购买 nike

我在项目中使用了 4 个图像..运行时结果:

* Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '* -[__NSArrayM insertObject:atIndex:]: object cannot be nil' *** First throw call stack:

我的代码:

NSArray *imageNames= @[@"jake_2.png",@"jake_3.png",@"jake_4.png",@"jake_5.png "];
// Do any additional setup after loading the view, typically from a nib.
NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++)
{
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
UIImageView *slowAnimationImageView = [[UIImageView alloc] initWithFrame:CGRectMake(160, 95, 86, 193)];
slowAnimationImageView.animationImages = images;
slowAnimationImageView.animationDuration = 5;
[self.view addSubview:slowAnimationImageView];
[slowAnimationImageView startAnimating];
}

最佳答案

您遇到问题是因为您在数组中提供的图像名称在资源中不可用。检查数组中的最后一个对象:@"jake_5.png "。里面有一个额外的空间。请删除它。这就是导致此问题的原因。

更新:

对于动画,您需要在将所有图像添加到您的imageArray 后设置它。请引用此代码以获得帮助并进行更改:

NSMutableArray *images = [[NSMutableArray alloc] init];
for (int i = 0; i < imageNames.count; i++)
{
[images addObject:[UIImage imageNamed:[imageNames objectAtIndex:i]]];
}

slowAnimationImageView.animationImages = images;
slowAnimationImageView.animationDuration = 5;
[slowAnimationImageView startAnimating];

希望对你有帮助

关于ios - NSArrayM insertObject :atindex 异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30635295/

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