在完成之前,在完成脚本之前运行以下脚本



我尝试在@ibaction func内部运行独立的多个语句。但是我想先完成第一任命(我在暂停该过程中放置一个警报块),然后运行第二inf-statement,然后运行REST脚本。我的代码看起来像这样:

@IBAction func onDone(_ sender: Any) {
   if var1.count > 0 {
     let block: DTAlertViewButtonClickedBlock = {(alertView, buttonIndex, cancelButtonIndex) in
     //Do somethings
     }
     DTAlertView(block: block, title: "Do somethings?", cancelButtonTitle: "Cancel", positiveButtonTitle: "Let's do it!").show()
   }
   if var2.count > 0 {
     //Do another things
   }
   _ = navigationController?.popViewController(animated: true)
}

但Xcode似乎在PopviewController中在PopviewController中运行的第一任命令和第二个IF-Statement不等我完成了警报块。

有人遇到同样的问题吗?我应该在代码中放置什么,或者我的代码有不正确的内容?

您需要将第二个if移入Alter按钮处理程序中。

@IBAction func onDone(_ sender: Any) {
    if var1.count > 0 {
        let block: DTAlertViewButtonClickedBlock = {(alertView, buttonIndex, cancelButtonIndex) in
            //Do something
            if var2.count > 0 {
                //Do another things
            }
            _ = navigationController?.popViewController(animated: true)
        }
        DTAlertView(block: block, title: "Do somethings?", cancelButtonTitle: "Cancel", positiveButtonTitle: "Let's do it!").show()
    }
}

最新更新