2017-01-18 5 views
0

내 앱에는 모달로 제공되는보기 컨트롤러가 있습니다. 이 뷰 컨트롤러에는 테이블 뷰가 있습니다. 사용자가 테이블 뷰에서 선택을 할 때마다 View Controller를 닫습니다.모달보기 컨트롤러를 해제하면 잠시 동안 앱이 정지됩니다. swift 3

문제는 해제 기능이 호출 되더라도 긴 지연 (5-7 초) 후에보기 컨트롤러가 해제되거나 해제되지 않는 경우가 있습니다. 어떤 도움을 매우 높이 평가된다

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) 
{ 
    if tableView == self.quarterTableView 
    { 
     self.delegate?.modalViewController(modalVC: self, dismissedWithValue:self.quarterPeriods[indexPath.row]) 
    } 
    else if tableView == self.monthTableView 
    { 
     self.delegate?.modalViewController(modalVC: self, dismissedWithValue: self.monthPeriods[indexPath.row]) 
    } 

    Print("didSelectRowAt dismiss") 

    self.dismiss(animated: true) { 
     Print("finished") 
    } 
} 

:

여기 내 코드입니다.

편집 :

내가 사용하여 문제를 해결 :

DispatchQueue.main.async 
{ 
    self.dismiss(animated: true) { 
     DDLogDebug("finished") 
    } 
} 

은 그렇게함으로써 수행 어떤 해가 있습니까?

+1

Eugene, 배경 대기열에서 해고를 호출하지 않는 한, 디스패치 메인 블록 내에서 호출하지 않아도됩니다. (이유가 알려지지 않은 경우) 원본 코드에서 Thread.isMainThread를 인쇄 해보고 내용을 확인하십시오. – Chris

답변

1

당신이 바로 발생하는 UI에 뭔가를하려는 경우 파견을 DispatchQueue

DispatchQueue.main.async(execute: { 

}) 
1

를 사용하려고, 주요 큐

DispatchQueue.main.async(execute: { 
    self.dismiss(animated: true) { 
    Print("finished") 
}) 
1

전혀 해를 끼치에 그것을 실행합니다. 주 스레드가 동시에 두 개의 작업을 수행하게합니다.