gpt4 book ai didi

iphone - NSData 和 NSArray -[__NSArrayM 长度]

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

我不知道这里发生了什么,但这段代码抛出异常。基本上我将 NSData 存储到一个数组中,然后检索它以在 UIImageView 中使用。这是代码。

    imagesDataArray = [[NSMutableArray alloc] init];
NSArray *imgDataArr = [[NSArray alloc] initWithArray:imageDataArray];
for(int i = 0; i < [imgDataArr count]; i++)
{
NSLog(@"%@",[imgDataArr objectAtIndex:i]);
UIImage *thumbImage = [[UIImage alloc] initWithData: [imgDataArr objectAtIndex:i]]; //this throws the exception
[imagesDataArray addObject:thumbImage];
[thumbImage release];
}
[imgDataArr release];

如您所见,我在 NSLog 中使用的相同代码 [imgDataArr objectAtIndex:i] 工作正常,但当我将它与 initWithData 配对时,它变得异常。这是错误日志。

    2011-10-17 15:56:47.008 myapp[39498:b303] -[__NSArrayM length]: unrecognized   
selector sent to instance 0x4c98420
2011-10-17 15:56:47.009 myapp[39498:b303] *** Terminating app due to uncaug

最佳答案

检查你的数组名.imagesDataArray

imagesDataArray = [[NSMutableArray alloc] initWithObjects:@"image1.png",@"image2.png",@"image3.jpg",@"image4.png",@"image6.png",@"image7.png",nil];
NSArray *imgDataArr = [[NSArray alloc] initWithArray:imagesDataArray];
for(int i = 0; i < [imgDataArr count]; i++)
{
NSLog(@"%@",[imgDataArr objectAtIndex:i]);
UIImage *thumbImage = [[UIImage alloc] initWithData: [imgDataArr objectAtIndex:i]]; //this throws the exception
[imagesDataArray addObject:thumbImage];
[thumbImage release];
}
[imgDataArr release];

关于iphone - NSData 和 NSArray -[__NSArrayM 长度],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7790872/

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