- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
在我的 iPhone 应用程序中,我正在尝试使用 uicollectionView 实现一个图片库。当 <20 张图像存储在图库中时它工作正常但是当我存储多个图像(大于 20 个)时应用程序崩溃。请帮助我。谢谢提前。
错误:
Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x7fabb400> was mutated while being enumerated.'
*** First throw call stack:
(
0 CoreFoundation 0x042ea946 __exceptionPreprocess + 182
1 libobjc.A.dylib 0x03660a97 objc_exception_throw + 44
2 CoreFoundation 0x042ea1e6 __NSFastEnumerationMutationHandler + 166
3 CoreFoundation 0x041da052 -[NSArray containsObject:] + 178
4 AtSceneDebug 0x001ce9a9 -[GalleryCollectionViewController loadImageFromAppSupport:] + 201
5 AtSceneDebug 0x001c5de2 __73-[GalleryCollectionViewController collectionView:cellForItemAtIndexPath:]_block_invoke + 98
6 libdispatch.dylib 0x03cca30a _dispatch_call_block_and_release + 15
7 libdispatch.dylib 0x03ceae2f _dispatch_client_callout + 14
8 libdispatch.dylib 0x03cd310f _dispatch_root_queue_drain + 634
9 libdispatch.dylib 0x03cd487e _dispatch_worker_thread2 + 45
10 libsystem_pthread.dylib 0x04056dab _pthread_wqthread + 336
11 libsystem_pthread.dylib 0x0405acce start_wqthread + 30
)
libc++abi.dylib: terminating with uncaught exception of type NSException
代码:
GalleryCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"GalleryCollectionViewCellID" forIndexPath:indexPath];
if(indexPath.row==0)
{
Photo *photo=[self.photoSource.photos objectAtIndex:indexPath.row];
cell.selectionImageView.hidden=YES;
[cell.galleryImageView setImage:[UIImage imageNamed:[photo.mURLLarge lastPathComponent]]];
return cell;
}
Photo *photo=[self.photoSource.photos objectAtIndex:indexPath.row];
if(self.mItemType==ITEM_TYPE_PHOTO)
{
NSLog(@"index of coll.......%d",indexPath.row);
UIImage *image = [_imageCache objectForKey:photo.mURLThumb];
if(image)
{
//[cell.galleryImageView setImage:[self loadImageFromAppSupport:photo.mURLLarge]];
[cell.galleryImageView setImage:image];
}
else
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
UIImage *image = [self loadImageFromAppSupport:photo.mURLThumb];
if(image)
{
dispatch_async(dispatch_get_main_queue(), ^{
GalleryCollectionViewCell *cell =(GalleryCollectionViewCell*)[self.collectionView cellForItemAtIndexPath:indexPath];
if(cell)
{
cell.galleryImageView.image = image;
}
});
[_imageCache setObject:image forKey:photo.mURLThumb];
}
});
}
}
else
{
[cell.galleryImageView setImage:[self loadImageFromAppSupport:photo.mURLThumb]];
}
if(indexPath.row==0)
{
cell.selectionImageView.hidden=YES;
}
else if(self.isEditing && photo.isMarkedForDeletion && indexPath.row!=0)
{
cell.selectionImageView.hidden=NO;
[cell.selectionImageView setImage:[UIImage imageNamed:@"red_led"]];
}
else if (self.isEditing && !photo.isMarkedForDeletion && indexPath.row!=0)
{
//[cell.selectionImageView setImage:[UIImage imageNamed:@"green_led"]];
cell.selectionImageView.hidden=YES;
}
else if(!self.isEditing && photo.isMarkedForDeletion && indexPath.row!=0)
{
cell.selectionImageView.hidden=YES;
}
else if(!self.isEditing && !photo.isMarkedForDeletion && indexPath.row!=0)
{
cell.selectionImageView.hidden=YES;
}
if (!self.isEditing)
{
CGFloat xx=cell.frame.origin.x;
CGFloat yy=cell.frame.origin.y;
CGRect frame = cell.frame;
frame.origin.x = 500; // new x coordinate
frame.origin.y = 0; // new y coordinate
cell.frame = frame;
[UIView animateWithDuration:0.0 animations:^{
CGRect frame = cell.frame;
frame.origin.x = xx; // new x coordinate
frame.origin.y = yy; // new y coordinate
cell.frame = frame;
}];
}
cell.layer.shouldRasterize = YES;
cell.layer.rasterizationScale = [UIScreen mainScreen].scale;
return cell;
最佳答案
当您在 2 个不同的线程/队列上使用 NSMutable 并且一个正在枚举一个而另一个正在从中添加/删除元素时,通常会抛出此错误。你不应该在多线程环境中使用 NSMutableObject。您的来电:
[_imageCache setObject:image forKey:photo.mURLThumb];
是失败的原因,您正在更改调度队列中的可变对象,同时在主线程中访问它。将此调用移至“if(cell)”部分上方(或 dispatch_get_main_queue block 中的任何其他位置)将解决此问题。
关于ios - 'NSGenericException',原因 : Collection <__NSArrayM: 0x7fabb400> was mutated while being enumerated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28107809/
我目前正在尝试弄清楚如何使用iOS 10的AVCapturePhotoOutput方法,但遇到了麻烦。我觉得自己即将做对,但继续收到错误消息: 由于未捕获的异常“NSGenericException”
简单这是我的代码 func showMessageView(){ let leftConstraint = messageView.leftAnchor.constraintEqualToAn
我正在使用 UIImagePickerController 从 iphone 库加载保存的照片。但是当我向上或向下滚动图像时,我的应用程序崩溃了.. 我收到以下错误: 2011-04-21 14:26
我正在使用 NSMutableArray 来存储在我的 View 中显示的一些 UIView 对象。我正在使用 NSTimer 连续调用一个方法来检查该数组的内容并收到一些错误。 这是控制台的堆栈跟踪
这是我在出现 SKScene 时看到的错误,此错误发生随机并且无法复制 * 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“* 集合 在枚举时发生了变异。” 这是怎么回
以下代码: listViewPopoverControllerOL = [[UIPopoverController alloc] initWithContentViewController:myBra
我目前正在尝试弄清楚如何使用 iOS 10 的 AVCapturePhotoOutput 方法,但遇到了困难。我觉得我即将做对,但仍然收到错误: Terminating app due to unca
由于未捕获的异常“NSGenericException”而终止应用 Terminating app due to uncaught exception 'NSGenericException', re
我正在开发一个在 iPhone 上运行的应用程序运行良好,但是当我尝试在 iPad 上运行时它崩溃了 这是我的代码: - (void)parseCountryStates:(NSDictionary
在我的 iPhone 应用程序中,我正在尝试使用 uicollectionView 实现一个图片库。当 was mutated while being enumerated.' *** First
我正在努力寻找和思考这个问题,但我找不到解决它的最佳方案!!我不明白这是什么意思?! Terminating app due to uncaught exception 'NSGenericExcep
我正在使用 [self.view addSubview:myView] 添加一个 View 作为 subview .这在纵向模式下工作正常。但是,它在风景中根本不起作用。如何以编程方式添加布局约束?
我在尝试运行我的应用程序并拍摄照片时不断收到上述错误消息。 我是编程新手,所以如果有人能提供帮助那就太棒了。 这是我的代码 import UIKit import AVFoundation impor
当我的代码如下所示时,我遇到“集合在枚举时发生变化”异常: NSString *poiStr = nil; int SuccessValue=0; NSMutableArray* po
有时我的应用程序因显示 * Collection 在被枚举时发生了变异而崩溃。这一直发生在同一行代码中。请帮助我解决这个问题。我坚持这一点。该应用程序在推送我的代码的 View Controller
我得到这个 NSGenericException 原因是 Collection was mutated while being enumerated 即使我实际上并没有在我的代码中使用快速枚举。 当
我不明白问题所在,但我猜是 Storyboard 中的问题(在我的限制下,因为有时对象不在它们必须在的位置)。 * 由于未捕获的异常“NSGenericException”而终止应用程序,原因:“*
我正在尝试从数组中删除重复的对象。 NSMutableArray* filterResults = [[NSMutableArray alloc] init]; BOOL copy;
我正在使用 Alamofire,在我的应用程序在模拟器上运行几个小时后,我遇到了崩溃并出现此错误。 *** Terminating app due to uncaught exception 'NSG
所以我正在制作一个包含 5 个 View Controller 的应用程序,第一个嵌入在 UINavigationController 中,前 4 个 View Controller 之间的连接工作正
我是一名优秀的程序员,十分优秀!