问题描述
我正在创建一个使用Facebook SDK验证用户的应用程序。我试图在一个单独的课程中巩固Facebook逻辑。以下是代码(为简单起见):
I'm creating an app that uses the Facebook SDK to authenticate users. I'm trying to consolidate the facebook logic in a separate class. Here is the code (stripped for simplicity):
import Foundation
class FBManager {
class func fbSessionStateChane(fbSession:FBSession!, fbSessionState:FBSessionState, error:NSError?){
//... handling all session states
FBRequestConnection.startForMeWithCompletionHandler { (conn: FBRequestConnection!, result: AnyObject!, error: NSError!) -> Void in
println("Logged in user: \n\(result)");
let storyboard = UIStoryboard(name: "Main", bundle: NSBundle.mainBundle())
let loggedInView: UserViewController = storyboard.instantiateViewControllerWithIdentifier("loggedInView") as UserViewController
loggedInView.result = result;
//todo: segue to the next view???
}
}
}
我使用上面类方法来检查会话状态的变化,并且可以正常工作。
I'm using the above class method to check session state changes, and it works fine.
Q:一旦我拥有用户的数据,我怎么能
Q: Once I have the user's data, how can I segue to the next view from within this custom class?
编辑:只是为了清楚,我在故事板上有一个标识符,我试图找到一个方法来执行一个不是视图控制器的类的一个方法。
just to be clear, I have a segue with identifier on the storyboard, and I'm trying to find a way to perform a segue from a class which is not the view controller
推荐答案
如果你的段落存在于您可以使用以下两种视图之间的段标识符进行调用:
If your segue exists in the storyboard with a segue identifier between your two views, you can just call it programmatically using:
performSegue(withIdentifier: "mySegueID", sender: nil)
对于旧版本:
performSegueWithIdentifier("mySegueID", sender: nil)
你也可以这么做:
presentViewController(nextViewController, animated: true, completion: nil)
或者如果您在导航控制器中: p>
Or if you are in a Navigation controller:
self.navigationController?.pushViewController(nextViewController, animated: true)
这篇关于IOS - 如何以编程方式使用swift的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!