변수를 선언하고 UIAlertAction 내에 값을 설정하려고합니다. 나는 을 탭하면 "내가 거기 갈거야" 버튼 내 아래 코드의 출력은 다음과 같습니다스위프트 : 변수 값을 UIAlertAction 내부로 설정합니다.
1 thisCustomerRequesting : 사실
3 thisCustomerRequesting : 거짓
당신이 말할 수 있습니까 이유 "2 thisCustomerRequesting : ...." 출력에 누락되었습니다. 왜 "3 thisCustomerRequesting : false"이 사실 일 것으로 예상되는 동안 거짓입니다.
var thisCustomerRequesting = false
if thisCustomerRequesting == false {
let alert = UIAlertController(title: "title", message: "message", preferredStyle: .alert)
alert.addAction(UIAlertAction(title: "I am going there", style: .destructive, handler: {
(alertAction1: UIAlertAction) in
thisCustomerRequesting = true
print("1 thisCustomerRequesting: \(thisCustomerRequesting)")
}))
alert.addAction(UIAlertAction(title: "Close", style: .default,handler: nil))
self.present(alert, animated: true, completion: nil)
print("2 thisCustomerRequesting: \(thisCustomerRequesting)")
}
print("3 thisCustomerRequesting: \(thisCustomerRequesting)")
내 콘솔에 2-3-1의 순서가 표시됩니다. – holex