我是 Swift Mac App 开发的新手,我在登录 URLRequest 后从登录窗口到显示主窗口,并在新的主窗口中创建另一个 URLRequest 时遇到了麻烦。如果我只是从一个窗口进入而不进行登录 URLRequest,它可以正常工作。
func loadMainView() {
self.view.window?.close()
let storyboard = NSStoryboard(name: "Main", bundle: nil)
let mainWindowController = storyboard.instantiateController(withIdentifier: "MainViewController") as! NSWindowController
if let mainWindow = mainWindowController.window {
let application1 = NSApplication.shared()
application1.runModal(for: mainWindow)
}
}
func tryLogin(_ username: String, password: String ) {
Staff.login(username: self.username.stringValue, password: self.password.stringValue) { (completed, result, staff) in
// DispatchQueue.main.async {
if completed {
if result == .Success && staff != nil {
DispatchQueue.main.async(execute: {
self.loadMainView()
})
} else {
self.dialogOKCancel(message: "Error", text: "Your credentials are incorrect")
}
} else {
print("error")
}
}
}
HTTPSConnection.httpGetRequestURL(token: token, url: digialOceanURL, mainKey: mainKeyVal) { ( complete, results) in
DispatchQueue.main.async {
if complete {
}
}
}
我尝试在没有执行的情况下调用 self.loadMainView(),但仍然不走运。
任何帮助表示赞赏。谢谢