때때로 비동기 스레드의 오류 경고를 표시하는 함수를 호출하는 IBAction
이 있습니다. 이 시뮬레이터에서 "작품"하지만이 오류가있어 :이 오류가 표시되면Swift 3.0의 비동기 스레드에서 UIAlertController 호출
CoreAnimation: warning, deleted thread with uncommitted CATransaction; set CA_DEBUG_TRANSACTIONS=1 in environment to log backtraces.
을, 나는 메인 스레드 해제 UI를 업데이트하려고하고 있었고, 난 그것을 수정해야 깨달았다.
여기에 내가 전화 한 비동기 함수의 :
let queue = DispatchQueue(label: "com.adrianbindc.myApp.myFunction")
queue.async {
self.createArray()
switch self.arrayIsEmpty() {
case true:
// TODO: update on the main thread
self.displayAlert(alertTitle: "Error Title", alertMessage: "Error Message")
case false:
// Do Stuff Off the Main Queue
DispatchQueue.main.async{
switch someArray.count {
case 0:
// TODO: update on the main thread
self.displayAlert(alertTitle: "Another Error Title", alertMessage: "Another error message.")
default:
// Do other stuff
}
}
}
}
/**
Utility method to display a single alert with an OK button.
*/
func displayAlert(alertTitle: String, alertMessage: String) {
let alertController = UIAlertController(title: alertTitle, message: alertMessage, preferredStyle: .alert)
let okAction = UIAlertAction(title: "OK", style: .default, handler: nil)
alertController.addAction(okAction)
self.present(alertController, animated: false, completion: nil)
}
나는 내 displayAlert
기능의 앞에 @objc
을 추가하고 내에서이 같은 경고 함수를 호출 시도
시도했다 비동기 블록 :
self.performSelector(onMainThread: #selector(ViewController.displayAlert(alertTitle: "Error Title", alertMessage: "Error Message")), with: self, waitUntilDone: false)
하지만 컴파일러에서이 오류가 발생합니다.
Use of instance member 'displayAlert' on type 'ViewController'; did you mean to use a value of type 'ViewController' instead?
내 실수가 많은 부분에 대한 의견을 듣고 싶습니다. 읽어 주셔서 감사합니다.
'performSelector' 대신'DispatchQueue.main.async {displayAlert (alertTitle : "오류 제목", alertMessage : "오류 메시지")}}를 사용합니다. –
@AaronBrager 감사합니다. 그게 내가 끝내 준거야. 방금 내 답변을 게시 :) – Adrian