我的SignInViewController.swift中有一个类:
button.setImage(UIImage(named: "enter.png"), forState: [.Selected, .Highlighted])
我想使用变量signedIn来使用if-else语句对AppDelegate中的用户进行身份验证。目前,我有办法将viewcontroller设置为CustomTabBarController(自定义编程)或 SignInViewController(storyboard made)。 if语句基本上会说如果值为false,则将控制器设置为登录屏幕,如果是,则转到标签栏屏幕。
class CredentialState: NSObject {
static let sharedInstance = CredentialState()
var signedIn = false
var displayName: String?
var photoUrl: NSURL?
}
答案 0 :(得分:1)
如果我理解正确的话:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
FIRApp.configure()
// Override point for customization after application launch.
window = UIWindow(frame: UIScreen.mainScreen().bounds)
// check login state
if CredentialState.sharedInstance.signedIn {
// Main view controller is inside of customtabbarcontroller, which gives a tab overlay
window?.rootViewController = CustomTabBarController()
} else {
// Sets the main view to a storyboard element, such as SignInVC
let storyboard = UIStoryboard(name: "SignIn", bundle: nil)
let loginVC = storyboard.instantiateViewControllerWithIdentifier("SignInVC") as! SignInViewController
window?.rootViewController = loginVC
}
window?.makeKeyAndVisible()
return true
}
答案 1 :(得分:1)
我不太确定你在问什么,但我会试着回答这个问题。基本上你需要做的只是在CredentialState类上面放置这段代码:
credentialState : CredentialState = CredentialState()
通过这种方式,您可以从AppDelegate更改或检查signedIn变量。所以只需在AppDelegate文件中即可:
if(credentialState.signedIn == true) ...
希望我能回答你的问题