2016-03-21 124 views
0

所以我實現了一個FB登錄到我有鑑於controller.swift文件Segue公司新的視圖控制器

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 

    if error == nil 
    { 
     print("Login Successful") 
    } 
    else 
    { 
     print(error.localizedDescription) 
    } 

} 

下面從這一點來說,雖然我不知道如何/在哪裏調用一個函數來Segue公司的應用在成功登錄之後,我對swift很陌生,所以任何詳細的解釋都會很棒。

+0

最簡單的方法,在storyboar中添加一個segue d,分配一個標識符,然後調用'performSegueWithIdentifier' – zcui93

回答

0

你的代碼是好的,在同一時間,你需要實現performSegueWithIdentifier對於SEGUE

enter image description here

use segue identifier in Push Method and give the proper connection 

如果您正在使用Identifier,然後調用這一行,其中u需要 self.performSegueWithIdentifier( 「identifierName」,發送方:自)

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 

    if error == nil 
    { 
     print("Login Successful") 
     self.performSegueWithIdentifier("identifierName", sender: self) 
    } 
    else 
    { 
     print(error.localizedDescription) 
    } 

} 

選擇-2

if use `storyboard ID` with connection less 

例如

I have given segue identifier in SeconViewController as in the image.

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 

    if error == nil 
    { 
     print("Login Successful") 
      let second = self.storyboard?.instantiateViewControllerWithIdentifier("SecondViewControllerSegue") as? SecondViewController 
    self.navigationController?.pushViewController(second!, animated: true) 
    } 
    else 
    { 
     print(error.localizedDescription) 
    } 

} 
+0

你的問題已解決或不是 –

+0

是的一些哄騙後我終於得到了它謝謝 – bananibau5

+0

@ bananibau5 - 歡迎夥計 –

0

在故事板設置在屬性檢查器中,例如「showNexController」識別符聲明你的視圖控制器之間的賽格瑞並做到這一點:

func loginButton(loginButton: FBSDKLoginButton!, didCompleteWithResult result: FBSDKLoginManagerLoginResult!, error: NSError!) { 
    if (error) { 
    print("Process error") 
    } else if (result.isCancelled) { 
    print("Cancelled") 
    } else { 
    print("Logged in") 
    // Perform segue here 
    performSegueWithIdentifier("showNexController", sender: self) 
    } 
} 
+0

這樣保持它在同一個函數內嗎?不要創建一個新的功能? – bananibau5

+0

您需要在登錄成功時觸發segue,因此您只需在此閉包中調用performSegueWithIdentifier您可以創建一個單獨的函數,該函數執行SegueWithIdentifier加上您想添加的任何其他邏輯,但您仍然需要調用它在這封閉之內。 –

+0

如果您想在執行segue之前在登錄情況下執行更多操作,則可以聲明您的功能,否則請不要。 – Ro22e0