ios - 转至新的 View Controller

标签 ios swift ios9 segue

因此,我使用 viewcontroller.swift 文件中的以下内容实现了 FB 登录到我的应用程序

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

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

}

从这一点来看,虽然我不确定如何/在哪里调用函数来在成功登录后进行继续,但我对 swift 很陌生,所以任何详细的解释都会很棒。

最佳答案

你的代码没问题,同时你需要为segue实现performSegueWithIdentifier

enter image description here

use segue identifier in Push Method and give the proper connection

如果您使用Identifier,请在您需要的地方调用此行 self.performSegueWithIdentifier("identifierName", 发件人: self)

  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)
    }

}

关于ios - 转至新的 View Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36135229/

相关文章:

ios - iOS 8 中的旧金山字体

ios - CLLocationManager:allowDeferredLocationUpdates - 不断获取操作无法完成。 (kCLErrorDomain 错误 11。)

ios - 如何检查 subview Controller 是否存在

ios - 从行中删除表附件指示器

IOS 构建良好但在设备上运行时出错

IOS-如何将视频添加为 ViewController 背景并使用 swift 在运行时添加约束

ios - 升级到 xcode 7 后无法在设备上运行应用程序

iphone - 适用于 iOS 的富文本编辑器库

ios - Swift UNUsernotification applicationIconBadgeNumber 始终显示一个

node.js - Alamofire图像代码=-1016 "Failed to validate response due to unacceptable content type"