问题描述
您好,我无法将数据发送到NSSplitViewController.似乎在IOS开发中无法正常工作.
Hello i've got problems to send data to NSSplitViewController. It doesn't seems work like in IOS development.
firstController:
firstController:
class LoginController: NSViewController {
//.....
@IBAction func Login(_ sender: Any) {
//....
let story = NSStoryboard(name: NSStoryboard.Name(rawValue: "Main"),
bundle: nil).instantiateController(withIdentifier:
NSStoryboard.SceneIdentifier(rawValue: "SPLIT")) as!
NSSplitViewController
let vc : ContainerController = ContainerController();
vc.passedData = "karosas";
self.view.window?.contentViewController = story;
//....
}
//.....
}
第二个NSSplitViewController:
second NSSplitViewController :
import Cocoa
class ContainerController: NSSplitViewController {
var passedData = "";
override func viewDidLoad() {
super.viewDidLoad()
print(passedData);
print("nzn");
}
}
现在我正在尝试将数据发送到NSViewSplitController.我需要将数据传递到NSSplitViewController中的NSViewController.我确实尝试了许多不同的方法,但是我失败了.所以我认为我需要先将数据传递给SplitController,然后再传递给ViewController.但是我什至不能发送任何数据到NSSplitViewController.有人可以帮我吗?
Now i'm trying to send data to NSViewSplitController. I need to pass data to NSViewController which is in NSSplitViewController. I did try many different ways, but i failed. So i thought that i need to pass data first to SplitController and then to ViewController. But i can't even send any data to NSSplitViewController. Can someone help me?
推荐答案
如果LoginController和MenuController都在ContainerController中,则可以执行以下操作:
If the LoginController and the MenuController are both in the ContainerController, you could do something like:
LoginController
LoginController
import Cocoa
class LoginController: NSViewController {
//.....
@IBAction func Login(_ sender: Any) {
//....
self.userName = value["name"] as! String
let MenuVC = parent?.childViewControllers[1] as! MenuController // 0 or 1 depending on order in SplitView
MenuVC.passedData = self.username
self.view.window?.contentViewController = parent as! ContainerController
//....
}
//.....
}
MenuController
MenuController
import Cocoa
class MenuController: NSViewController {
var passedData = ""
override func viewDidLoad() {
super.viewDidLoad()
print(passedData)
print("nzn")
}
}
这篇关于将数据从NSViewController传递到NSSplitViewController中的另一个NSViewController?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!