0
我是iOS應用程序開發新手,我很難嘗試在視圖之間傳遞Facebook用戶信息。我的應用程序有2個視圖。我能夠使用this tutorial實現Facebook登錄,因爲你可能知道他們仍然沒有給予迅速的官方支持。在視圖之間傳遞Facebook用戶信息。 iOS Swift Xcode 6
這是我的視圖控制器:
// 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.
}
}
這是第二個視圖控制器:
// 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.
}
}
我需要顯示在第二視圖中的用戶名,如果可能,他的自畫像。我怎樣才能做到這一點?
非常感謝你 問候 缺口
有多種方法可以實現這一點。請參閱以下線程,其中包含解決您的問題的不同方法。所有在ObjectiveC中,但其中大多數也將在Swift中工作。 https://stackoverflow.com/questions/5210535/passing-data-between-view-controllers – Apfelsaft 2014-08-29 06:33:29