本文介绍了在视图之间传递Facebook用户信息。 iOS Swift Xcode 6的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS应用程序开发中是新的,我很难在视图之间传递Facebook用户信息。我的应用程序有2个视图。我可以使用,因为你可能知道他们仍然不会表示支持迅速。



这是我的视图控制器:

  // ViewController.swift 


import UIKit

class ViewController:UIViewController,FBLoginViewDelegate {

@IBOutlet var fbLoginView:FBLoginView!

覆盖func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从笔尖进行任何其他设置。
self.fbLoginView.delegate = self
self.fbLoginView.readPermissions = [public_profile,email,user_friends]
}

// FACEBOOK DELEGATE METHODS
func loginViewShowingLoggedInUser(loginView:FBLoginView!){
println(User Logged In)
println(这是执行segue的地方)
self。 performSegueWithIdentifier(gotoMenu,sender:self)

}

func loginViewFetchedUserInfo(loginView:FBLoginView !, user:FBGraphUser){
println(user.name)
}

func loginViewShowingLoggedOutUser(loginView:FBLoginView!){
println(User Log Out Out)
}

func loginView loginView:FBLoginView !, handleError:NSError){
println(Error:\(handleError.localizedDescription))
}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理可以重新创建的任何资源。
}


}

这是第二个视图控制器:

  // SecondViewController.swift 

import UIKit

class SecondViewController:UIViewController {

@IBOutlet weak var greeting:UILabel!


覆盖func viewDidLoad(){
super.viewDidLoad()
//加载视图后,通常从笔尖进行任何其他设置。

}

覆盖func didReceiveMemoryWarning(){
super.didReceiveMemoryWarning()
//处理可以重新创建的任何资源。
}


}

我需要在第二个视图中显示用户名,如果可能,显示他的个人资料图片。如何做到这一点?



非常感谢你
问候语
nick

解决方案

在您的LoginViewController中,只需覆盖prepareForSegue:像这样...

  //在导航时你经常想做一点准备
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue .identifier isEqualToString:@gotoMenu]){
SecondViewController * vc = segue.destinationViewController;
vc.username = self.username; //这是你传递数据的地方!
}
}

我知道这是客观C,但所有方法名称在Swift中完全相同。


I am new in iOS app development and I'm having a hard time trying to pass facebook user information between views. My app has 2 views. I was able to implement facebook login using this tutorial because as you might know they still dont give oficial support to swift.

This is my view controller:

//  ViewController.swift


import UIKit

class ViewController: UIViewController, FBLoginViewDelegate{

    @IBOutlet var fbLoginView : FBLoginView!

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        self.fbLoginView.delegate = self
        self.fbLoginView.readPermissions = ["public_profile", "email", "user_friends"]
    }

    // FACEBOOK DELEGATE METHODS
    func loginViewShowingLoggedInUser(loginView : FBLoginView!) {
        println("User Logged In")
        println("This is where you perform a segue.")
        self.performSegueWithIdentifier("gotoMenu", sender: self)

    }

    func loginViewFetchedUserInfo(loginView : FBLoginView!, user: FBGraphUser){
        println(user.name)
    }

    func loginViewShowingLoggedOutUser(loginView : FBLoginView!) {
        println("User Logged Out")
    }

    func loginView(loginView : FBLoginView!, handleError:NSError) {
        println("Error: \(handleError.localizedDescription)")
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

This is the second view controller:

//  SecondViewController.swift

import UIKit

class SecondViewController: UIViewController {

    @IBOutlet weak var greeting: UILabel!


    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.

    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }


}

I need to show the user name in the second view and if possible his profile picture. How can I do this?

Thanks you very muchGreetingnick

解决方案

In your LoginViewController simply override prepareForSegue: like so...

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([segue.identifier isEqualToString:@"gotoMenu"]) {
         SecondViewController *vc = segue.destinationViewController;
         vc.username = self.username; // This is where you pass the data!!
    }
}

I know this is on objective-C but all the method names are exactly the same in Swift.

这篇关于在视图之间传递Facebook用户信息。 iOS Swift Xcode 6的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 04:07