0

나는 현재 내 애플 리케이션에 MWPhotoBrowser를 사용하고있어 나는 다음과 같은 오류 얻을 이미지를 빠르게 스크롤 할 때 : 나는 현재 로컬 응용 프로그램에 저장된 이미지를로드하고있어iOS : 사진을 신속하게 스크롤 할 때 오류가 발생합니까?

Received memory warning. 
2014-02-17 16:42:35.117 App[10803:60b] *** Terminating app due to uncaught exception 'NSGenericException', reason: '*** Collection <__NSArrayM: 0x156f3160> was mutated while being enumerated.' 
*** First throw call stack: 
(0x2e71de83 0x38a7a6c7 0x2e71d971 0x151167 0x15139b 0x311643ff 0x3116446f 0x31164665 0x31164805 0x3111ea67 0x38f5f0af 0x38f6072f 0x38f61959 0x2e6e85b1 0x2e6e6e7d 0x2e651471 0x2e651253 0x3338b2eb 0x30f06845 0xff035 0x38f73ab7) 
libc++abi.dylib: terminating with uncaught exception of type NSException 

합니다.

- (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent { 
    for (id p in _photos) { 
     if (p != [NSNull null]) { 
      if (preserveCurrent && p == [self photoAtIndex:self.currentIndex]) { 
       continue; // skip current 
      } 
      [p unloadUnderlyingImage]; 
     } 
    } // Release photos 
} 

이 어떤 도움을 크게 감상 할 수있다 :

이 예외를 던지는 방법입니다!

답변

1

은 당신이 사용하는 MWPhotoBrowser 정확하게 버전 모르겠지만, 최신 하나 here에서 releaseAllUnderlyingPhotos: 방법은 읽

NSArray *copy = [_photos copy]; 
    for (id p in copy) { 

:

- (void)releaseAllUnderlyingPhotos:(BOOL)preserveCurrent { 
    // Create a copy in case this array is modified while we are looping through 
    // Release photos 
    NSArray *copy = [_photos copy]; 
    for (id p in copy) { 
     if (p != [NSNull null]) { 
      if (preserveCurrent && p == [self photoAtIndex:self.currentIndex]) { 
       continue; // skip current 
      } 
      [p unloadUnderlyingImage]; 
     } 
    } 
    // Release thumbs 
    copy = [_thumbPhotos copy]; 
    for (id p in copy) { 
     if (p != [NSNull null]) { 
      [p unloadUnderlyingImage]; 
     } 
    } 
} 

이 두 줄을 유의하시기 바랍니다 _photos를 반복하기 전에 에서 수정 된 _photos에서이 반복을 보호하기 위해 새 배열 copy이 만들어집니다. 코드에서

, releaseAllUnderlyingPhotos:_photos 배열에서 바로 개체를 삭제되지만, 귀하의 경우와 같이이 배열은, 예를 들어, didReceiveMemoryWarning를 들어, 코드의 다른 부분에서 수정할 수 있습니다.

_photos 복사본을 반복 코드 releaseAllUnderlyingPhotos:에 수정하면 문제가 없어집니다.

관련 문제