早上好,
我有这堂课:
import Cocoa
class PopOverDetails: NSViewController {
var dID = String()
@IBOutlet weak var txtEmail: NSTextField!
public func fillDetails (ID:NSManagedObjectID) {
print("=== fillDetails ===")
print(ID)
dID = "\(ID)"
}
override func viewDidLoad() {
print("=== viewDidLoad ===")
print(dID)
}
}
我从另一个视图控制器调用该函数
let Controller = PopOverDetails()
Controller.fillDetails(ID: list[0].objectID)
al工作正常,但问题是: 在我的函数fillDetails中,我得到了我从视图控制器“发送”的objectID值。
但我无法在viedidload中使用此值,因为它是空的。 这是我的输出:
=== fillDetails ===
0x40000b <x-coredata://7E006435-3E05-41F9-A3E4-CB8179A319A9/list/p1>
=== viewDidLoad ===
我的错误在哪里? :)
更新
let vcDetails = NSStoryboard(name: "Main", bundle: nil).instantiateController(withIdentifier: "PopoverDetails") as! NSViewController
popover.contentViewController = vcDetails
popover.show(relativeTo: tblView.rect(ofRow: tblView.selectedRow) , of: tblView, preferredEdge: .maxX)
}
答案 0 :(得分:1)
首先在PopOverDetails中声明变量,即&#34; id&#34;,然后
let storyBoard : UIStoryboard = UIStoryboard(name: "Main", bundle:nil)
let secondViewController = storyBoard.instantiateViewController(withIdentifier: "your_identifier") as! PopOverDetails
secondViewController.id = list[0].objectID
self.navigationController?.pushViewController(secondViewController, animated: true)
现在你可以在PopViewController的类中获取该变量