2014-03-31 30 views
3
Thread : Fatal Exception: NSRangeException 
0 CoreFoundation     0x2ff42f03 __exceptionPreprocess + 130 
1 libobjc.A.dylib    0x3a6d7ce7 objc_exception_throw + 38 
2 CoreFoundation     0x2fed6eff -[__NSOrderedSetM objectAtIndex:] + 202 
3 PhotosUI      0x369ab149 -[PUPhotosGridViewController assetAtIndexPath:] 
4 PhotosUI      0x369b55b7 -[PUPhotosGridViewController collectionView:shouldSelectItemAtIndexPath:] 
5 UIKit       0x3298e42b -[UICollectionView _selectItemAtIndexPath:animated:scrollPosition:notifyDelegate:] + 174 
6 UIKit       0x3298e36f -[UICollectionView _userSelectItemAtIndexPath:] + 154 
7 UIKit       0x3298e055 -[UICollectionView touchesEnded:withEvent:] + 380 
8 UIKit       0x328f8f97 forwardTouchMethod + 234 
9 UIKit       0x3276a541 _UIGestureRecognizerUpdate + 5528 
10 UIKit       0x327a2325 -[UIWindow _sendGesturesForEvent:] + 772 
11 UIKit       0x327a1c4b -[UIWindow sendEvent:] + 666 
12 UIKit       0x32776e75 -[UIApplication sendEvent:] + 196 
13 UIKit       0x32775541 _UIApplicationHandleEventQueue + 7120 
14 CoreFoundation     0x2ff0dfe7 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14 
15 CoreFoundation     0x2ff0d4af __CFRunLoopDoSources0 + 206 
16 CoreFoundation     0x2ff0bc9f __CFRunLoopRun + 630 
17 CoreFoundation     0x2fe767a9 CFRunLoopRunSpecific + 524 
18 CoreFoundation     0x2fe7658b CFRunLoopRunInMode + 106 
19 GraphicsServices    0x34de36d3 GSEventRunModal + 138 
20 UIKit       0x327d5891 UIApplicationMain + 1136 

有人知道這個錯誤嗎?我只知道當你從UIImagePickerController中的相機膠捲中選擇一張照片時會發生什麼。- [PUPhotoshotosGridViewController assetAtIndexPath:] NSRangeException

更新 代碼:

- (void)addPhotoFromSource:(UIImagePickerControllerSourceType)source { 
if (![UIImagePickerController isSourceTypeAvailable:source]) 
return; 
NSString* imageType = (__bridge NSString*)kUTTypeImage; 
if (![[UIImagePickerController availableMediaTypesForSourceType:source] containsObject:imageType]) 
return; 
self.pickerController = [[UIImagePickerController alloc] init]; 
self.pickerController.sourceType = source; 
self.pickerController.mediaTypes = [NSArray arrayWithObject:imageType]; 
self.pickerController.delegate = self; 
[self presentViewController:self.pickerController animated:YES completion:nil]; 
} 

更新 我didFinishPickingMediaWithInfo方法:

- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info { 
UIImage *imageOriginal = [info objectForKey:UIImagePickerControllerOriginalImage]; 
UIViewController* vc = [self.storyboard instantiateViewControllerWithIdentifier:@"Crop"]; 
vc.image = imageOriginal; 
[picker pushViewController:vc animated:YES]; 
[picker setNavigationBarHidden:YES animated:YES]; 
} 

我imagePickerControllerDidCancel方法:

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker 
{ 
[picker dismissViewControllerAnimated:YES completion:nil]; 
} 
+0

把代碼didfinishPicking .. – iPatel

+0

我在我的崩潰日誌中看到相同的問題。你能重現嗎?在什麼情況下? –

回答

1

它在ios 7.x上重現。 重現步驟:

  1. 在應用程序中打開圖像選擇器。
  2. 打開「相機膠捲」。
  3. 按主頁按鈕(您不應該終止應用程序)。
  4. 轉到「照片」。
  5. 刪除最後的照片。
  6. 打開應用程序。

要解決它,我訂閱通知UIApplicationDidEnterBackgroundNotification並刪除UIImagePickerViewController。

if ([self _isIOS7]) 
{ 
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_applicationDidEnterToBackgroundNotification:) name:UIApplicationDidEnterBackgroundNotification object:nil]; 
} 
... 

- (void)_applicationDidEnterToBackgroundNotification:(NSNotification*)notificaiton 
{ 
    if ([self.owner presentedViewController] != nil) 
    { 
     [self _dismissImagePicker:NO]; 
    } 
}