2015-05-15 70 views
0

我有下面的代碼,當用戶註冊時顯示一個警告框。在用戶與Alert Box按鈕交互之後(即我們走),我需要觸發一個Segue(現在稱爲someSegue),以便它可以將用戶重定向到登錄頁面。iOS Swift - 無法觸發segue

用戶單擊警告框按鈕後沒有任何事情發生。我錯過了什麼?那裏是自我嗎?如果我刪除自己它不起作用,Xcode抱怨。

user.signUpInBackgroundWithBlock { 
        (succeeded, error) -> Void in 
        if error == nil { 
         // Hooray! Let them use the app now. 

         let delay = 4.5 * Double(NSEC_PER_SEC) 
         let time = dispatch_time(DISPATCH_TIME_NOW, Int64(delay)) 
         dispatch_after(time, dispatch_get_main_queue()) { 
          actInd.stopAnimating() 
          var alert = UIAlertController(title: "Congratulations!", message: "Your account was successfully created! You will be required to login with your credentials.", preferredStyle: UIAlertControllerStyle.Alert) 
          alert.addAction(UIAlertAction(title: "Let's Go!", style: UIAlertActionStyle.Default, handler: nil)) 
          self.presentViewController(alert, animated: true, completion: nil) 
          self.performSegueWithIdentifier("someSegue", sender: self) 
         } 



        } else { 
         // Show the errorString somewhere and let the user try again. 
        } 
       } 
+0

嘗試調用''裏面dispatch_async performSegueWithIdentifier'(dispatch_get_main_queue的處理器參數( ),{})' – boidkan

回答

0

如果要執行的代碼塊按下警報按鈕後,你需要傳遞塊的addAction方法

alert.addAction(UIAlertAction(title: "Let's Go!", style: UIAlertActionStyle.Default, handler: { (action: UIAlertAction!) in 
     self.performSegueWithIdentifier("someSegue", sender: self) 
    }))