2016-12-26 8 views
0

@IBAction funcの中で独立した複数のif文を実行しようとしています。しかし、私は最初のif文を終了したい(私は、プロセスを一時停止するための警告ブロックを置く)2番目のif文を実行してから、残りのスクリプトを実行したい。ステートメントを完了する前に次のスクリプトを実行します。

@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は私に警告ブロックを終了待ちません同じ時間にif文popViewControllerにおけるif文と第二第一に実行するように見える:私のコードは次のようになります。

いずれにも同じ問題がありますか?コードに何を入れるべきですか、コードに何か誤りがありますか?

答えて

0

第2のifを変更ボタンハンドラ内に移動する必要があります。

@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() 
    } 
} 
+0

var2.countはvar1.countに依存しません。 var1.countとvar1.countの両方を入れる必要がありますか? –

+0

はい、チェックする場合は、var2を繰り返す必要があります。 – rmaddy

関連する問題