我是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()而没有执行,但仍然没有运气。
任何帮助表示赞赏。谢谢
答案 0 :(得分:0)
不要在模态中运行主视图,模态应该用于对话框。因此,您可以在模态中运行登录视图(并通过在应用程序上调用stopModal
来完成它)。在这种情况下,您可以使用像loadLoginView
这样的smth,它将与您当前的loadMainView
具有相似的实现(但没有此self.view.window?.close()
调用。并且主视图将在应用程序启动时从nib加载。但是你必须发布一些代码(你的应用程序初始化看起来如何?)以获得帮助。