2016-03-28 13 views
-1

ではないので、私は私が作成したタスクにユーザーを送信します。試みが提示する<UIAlertController:>の<のViewController:>そのビュー私はResearchKitを使用してプロジェクトに取り組んでいますウィンドウ階層

let taskViewController = ORKTaskViewController(task: SurveyTask, taskRunUUID: nil) 
taskViewController.delegate = self 
presentViewController(taskViewController, animated: true, completion: nil) 

私は前に警告を表示しようとすると、私は、問題が発生した。ここ

func taskViewController(taskViewController: ORKTaskViewController, didFinishWithReason reason: ORKTaskViewControllerFinishReason, error: NSError?) { 
    switch reason { 
     case .Completed: 

... }

:ユーザーは調査を終了したとき、彼はに入りますViewControllerに...:UIAlertControllerを提示する

試み:

taskViewController.dismissViewControllerAnimated(true, completion: nil) 
は、私は以下のエラーを取得...そのビューウィンドウ階層

にI方法の任意のアイデアではありませんViewControllerを却下する前にアラートを表示することができますか?

let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert) 
alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil)) 
presentViewController(alertView, animated: true, completion: nil) 

EDIT::私は警告のために、以下の使用

コードは以下の通りです:

if let httpResponse = response as? NSHTTPURLResponse { 
       print("HTTP response: \(httpResponse.statusCode)") 
       if httpResponse.statusCode == 201 { 
        taskViewController.dismissViewControllerAnimated(true, completion: nil) 
       } 
      } else { 
       print("No HTTP response") 
       let alertView = UIAlertController(title: "Houps", message: "Could not connect to the server.", preferredStyle: .Alert) 
       alertView.addAction(UIAlertAction(title: "Ok", style: .Default, handler: nil)) 
       presentViewController(alertView, animated: true, completion: nil) 

      } 
+0

は、あなたの警告コントローラで「OK」ボタンのクリックでビューコントローラを閉じてもらえますか? –

+0

私はまだ解雇したくない、私は最初に警戒して見せたい。解任はうまくいっている。 問題がアラートを表示しています。 – asheyla

+1

はい、@ j.f。アラートに「OK」をタップすると却下すると言っています。 – tktsubota

答えて

0

あなたはtaskViewControllerにpresentViewControllerを呼び出す必要があります。ORKTaskViewControllerオブジェクト

taskViewController.presentViewController(alertView, animated: true, completion: nil) 
+0

はい、それだけです!できます!ありがとう、ステファン! – asheyla

0

あなたは提示するため、この

UIApplication.sharedApplication().keyWindow?.rootViewController?.presentViewController(yourAlertController, animated: true, completion: nil) 

を試すことができますUIAlertController

1

どのオブジェクトにhttpResponse定義が含まれていますか? presentViewController()呼び出しは、レスポンスが到着したときにビューがおそらくはビュー階層内になくなっているビューコントローラインスタンスで、自分自身を暗黙にキャプチャしているように見えます。

関連する問題

 関連する問題