2016-08-03 4 views
2
//Event created alert 
let alert = UIAlertController(title: "Event Created", message: "Event successfully created", preferredStyle: UIAlertControllerStyle.Alert); 
alert.addAction(UIAlertAction(title: "OK", style: UIAlertActionStyle.Default, handler:nil)); 
self.presentViewController(alert, animated: true, completion: nil); 

//Pop back to table 
self.navigationController!.popToRootViewControllerAnimated(true); 

このコードでは、アラートを作成し、アラートの直後にpopToRootViewControllerAnimatedメソッドを使用します。これは何らかの理由で動作しませんし、私が見つけた回避策はpresentViewControllerの完了の中でメソッドを呼び出すことです。alertのpresentviewcontrollerの後にpopviewcontrollerが動作しないのはなぜですか?

popureメソッドがclosureに入れられていない限り、presentViewControllerメソッドの後で動作しないのはなぜですか?

答えて

1

self.presentViewController(alert, animated: true, completion: nil)を呼び出すと、viewControllerはプレゼンテーションを実行します。それが進行しているときは、他のトランジション/プレゼンテーションを実行することはできません。

popToViewController:トランジション:私のマシン上でコードを実行するときに

は実は、私はこのログなった既存のトランジションやプレゼンテーションが行われている間に呼び出されると、ナビゲーションスタックは更新されません。

それ自体はかなり明確に説明する必要があります。代わりに、この行を完了クロージャに移動する必要があります。

3

私はあなたが、その場合には、のみOKにタップし、ユーザーの後popToRootを使用したいと思う:

// Created the alert 
let alert = UIAlertController(title: "Event Created", message: "Event successfully created", preferredStyle: UIAlertControllerStyle.Alert) 

// Create the action 
let OKAction = UIAlertAction(title: "OK", style: .Default) { (action: UIAlertAction!) -> Void in 
    self.navigationController!.popToRootViewControllerAnimated(true); 
    } 
// Add the action 
alert.addAction(OKAction) 

// Present the alert 
self.presentViewController(alert, animated: true, completion: nil) 

注:

  • あなたが本当に迅速に;を使用する必要はありません。
関連する問題