2015-01-27 1 views
1

내 코드 :NSOperationQueue cancelAllOperations이 작동하지 않을 때 viewWillDisappear

NSOperationQueue *queue; 

-(void)viewDidLoad 
{ 
    queue = [NSOperationQueue new]; 
    NSOperation* loadImgOp = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(refresh) object:nil]; 
    [queue addOperation:loadImgOp]; 

} 

-(void)refresh 
{ 
    [self operationFirst];   
    [self operationSecond]; 
    ... 
    [self operationFive]; 
    dispatch_async(dispatch_get_main_queue(), ^{ 
     [self.tableView reloadData]; 
    }); 

} 

- (void)viewWillDisappear:(BOOL)animated { 
    [super viewWillDisappear:animated]; 
    [queue cancelAllOperations];  
} 

나는 새의 ViewController 전화, 다음 - (무효) 새로 고침 작업을 계속합니다. cancelAllOperations가 작동하지 않습니다.

+0

"cancelAllOperations does not working"정확히 무엇을보고 있습니까? –

+0

이 메서드를 죽이고 싶습니다. - (void) refresh,이 ViewController를 종료 할 때 (새로운 ViewController를 호출 할 때). – runia

답변

3

현재 구성 할 수 없습니다. cancelled 속성을 추가하고 메소드 전체에서 확인해야합니다.

큐에서 호출을 취소하면 작업이 취소 된 것으로 표시되고 새 작업이 실행되지 않지만 실행중인 작업은 종료되지 않습니다. 취소를 관리하는 것은 각 작업에 달려 있습니다. 그때 그것은 이미 target 메소드를 호출 했으므로 아무 것도 할 수없는 호출입니다.

+0

내 코드에 표시 할 수 있습니까? – runia

+0

속성을 추가하는 것은 간단합니다. 그것을 BOOL로 만드십시오. YES로 설정하면 사라집니다. 이를 확인하고 호출하는 각 메소드 사이에 새로 고침에서 리턴하십시오. – Wain

관련 문제