2015-07-05 73 views
0

我正在嘗試一種簡單的註銷功能,其中視圖在用戶註銷後返回到我的登錄/註冊視圖。我曾嘗試使用這兩種方法,但每次應用程序崩潰。解析註銷功能

第一種方法:

@IBAction func signPressed(sender: AnyObject) { 

    PFUser.logOut() 

    let storyboard = UIStoryboard(name: "Main", bundle: nil) 
    let vc = storyboard.instantiateViewControllerWithIdentifier("ViewController") as! UIViewController 
    presentViewController(vc, animated: true, completion: nil) 
} 

第二種方法:

我創建了以下功能:

func loginSetup() { 

     if (PFUser.currentUser() == nil) { 

      let vc = ViewController() 
      self.presentViewController(vc, animated: true, completion: nil) 

      } 
} 

然後將其添加到我的登出功能:

@IBAction func signPressed(sender: AnyObject) { 

    PFUser.logOut() 

    self.loginSetup() 
} 

都崩潰了,給了我一個應用程序委託錯誤..這裏的問題是什麼?

這裏是給出錯誤的截圖:

https://40.media.tumblr.com/1f044ecbdd5059836b0a360d16af9846/tumblr_nqzsobll0o1tupbydo1_1280.png

+0

有什麼錯誤信息呢?您的信息不足以幫助我們。 –

+0

這完全沒有幫助,控制檯上是否印有任何內容? –

+0

不,控制檯上沒有任何東西,事實證明該方法是調用視圖控制器storyboard標識,而不是視圖本身的名稱。目標視圖標識爲空 –

回答

0

提供您所設置的根VC到登錄/註冊畫面。

func didTapSignOut(sender: AnyObject) 
{ 
    PFUser.logOut() 

    self.navigationController?.popToRootViewControllerAnimated(true) 
} 

然後,你可以調用一個UIButton IBAction爲這個功能,但我把它放在我的UINavigationBar的像這樣,

 self.navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Sign Out", style: .Plain, target: self, action: "didTapSignOut:") 
+0

現在該按鈕根本沒有任何功能,就像沒有插座的按鈕一樣 –

+0

確保您的插座全部連接在按鈕的插座選項卡中,並確保在您的代碼中有一個固定的灰色圓點旁邊UIButton操作,因爲您可能需要重新連接它。沒有理由我可以想到這個功能不起作用,所以請檢查你的請動手奧特萊斯。 – Jack

+0

其全部在那裏,我似乎無法找出問題 –