2016-07-15 8 views
0

검색을 구현했으며 사용자가 입력 한 모든 새로운 문자에 대해 performFetch:performBlock: 내부에서 시작되었습니다. 검색 문자열이 변경되면 이전 시작 블록을 취소하고 다시 시작하고 싶습니다. 어떻게 내가 그 블록에 대해 performBlock: 안에있는 블록을 취소하거나 알릴 수 있습니까? 내가 지금이performBlock 취소 방법 :

예제 코드 :

[myManagedObjectContext performBlock:^{ 
     // fetch from background queue 
     if([[self fetchedResultsController] performFetch:nil]) { 
      // update the view from the main queue 
      // don't do this if performBlock already got started again! but how? 
      [[NSOperationQueue mainQueue] addOperationWithBlock:^{ 
       // refresh UI 
      }]; 
     } 
    }]; 

답변

2

performBlock을 취소 할 API가 없습니다. 시작되면 완료 될 때까지 또는 코드 return이 나타날 때까지 계속됩니다.

진행 중에 가져 오기를 취소해야하는 경우 NSProgress을 통해 취소 할 수있는 NSAsynchronousFetchRequest을 조사하십시오. 비동기 가져 오기 요청 및 취소에 대한 설명은 WWDC 2014 Core Data session

+0

이 간단하고 명확한 답변에 감사드립니다. 'NSAsynchronousFetchRequest'는 좋은 해결책처럼 보입니다. –