2017-09-03 2 views
0

암호가 일치하면 경고 메시지를 표시하려고합니다.Alert - libC++ abi.dylib : NSException 유형의 catch되지 않은 예외로 종료합니다.

1) 웹 서비스가 호출되고 암호

2) 흐름이 displayAlert 함수가 호출됩니다

if(userPasswd == sysPasswd) 
    { 
     displayAlert(userMessage: "Welcome! You have been authenticated") 
     return 
    } 

암호 경기에 관련된 경우 조건을 입력을 반환 : 모든 아주 잘 작동 성공적으로 :

func displayAlert(userMessage: String) 
    { 
    // create the alert 
    let myAlert = UIAlertController(title: "Alert", message: userMessage, preferredStyle: UIAlertControllerStyle.alert) 

    // add an action (button) 
    myAlert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil)) 

    // show the alert 
    self.present(myAlert, animated: true, completion: nil) 
    } 

마지막 문이 실행될 때이 오류를 제공

libc++abi.dylib: terminating with uncaught exception of type NSException 

왜 이런 일이 발생합니까? 저는 스위프트에서 초보자이며 여전히 로프를 배우고 있습니다. 노란색 플래그 등은 없습니다.

+0

네트워크 메소드가 반환 될 때 'self'가 확실합니까? – the4kman

+0

정확한 오류 메시지를 보려면 디버거에서 예외 중단 점을 설정하십시오. –

+0

경고를 표시하는 동안 주 스레드에 있습니까? 나는 당신이 .. .. –

답변

0

사용자 인터페이스 요소는 주 스레드에서만 사용할 수 있습니다. 백그라운드 스레드에서 UI를 업데이트하려는 경우 DispatchQueue.main.async으로 호출하여 UI 호출을 래핑해야합니다.

func displayAlert() { 
    DispatchQueue.main.async { 
     let myAlert = UIAlertController(etc...) 
     ... 
    } 
} 
+0

. 알았다. – coderatlarge

관련 문제