【发布时间】:2018-01-21 01:41:55
【问题描述】:
如果应用程序第一次加载,我会尝试执行 segue。 我可以在调试器中看到我的打印消息,但是 Perform Segue 不起作用。我没有收到任何错误。 有人可以告诉我有什么问题吗?
import UIKit
import LocalAuthentication
let isFirstLaunch = UserDefaults.isFirstLaunch()
extension UserDefaults {
// check for is first launch - only true on first invocation after app install, false on all further invocations
// Note: Store this value in AppDelegate if you have multiple places where you are checking for this flag
static func isFirstLaunch() -> Bool {
let hasBeenLaunchedBeforeFlag = "hasBeenLaunchedBeforeFlag"
let isFirstLaunch = !UserDefaults.standard.bool(forKey: hasBeenLaunchedBeforeFlag)
if (isFirstLaunch) {
UserDefaults.standard.set(true, forKey: hasBeenLaunchedBeforeFlag)
UserDefaults.standard.synchronize()
}
return isFirstLaunch
}
}
class loginVC: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
if isFirstLaunch == false {
performSegue(withIdentifier: "setPassword", sender: self)
print("testFalse") }
else {
performSegue(withIdentifier: "setPassword", sender: self)
print("testTrue")}
// Do any additional setup after loading the view, typically from a nib.
}
【问题讨论】:
-
日志中打印了什么?
-
testTrue用于首次发布,testFalse用于其他发布? -
正确。日志的第一行是 testFalse
-
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {被解雇了吗? -
显示 segue 在哪里定义?例如,您是否尝试将其移至 viewDidAppear?
标签: ios swift xcode segue viewdidload