In IB I connect a button to a VC and set the segue kind to 'Popover'. Now I have a problem. How do I get the NSPopover and its delegate?
-(void)prepareForSegue:(NSStoryboardSegue *)segue sender:(id)sender {
NSLog(@"%s: %@", __func__, segue.destinationController);
NSViewController* vc = segue.destinationController;
}
I tested this:
- In the calling VC (class is InitialViewController), create a func:
func handleClosePopover() {
print("Popover was closed")
}
- Implement the delegate func popoverDidClose in the popoverController
class SeguedViewController: NSViewController, NSPopoverDelegate {
@IBOutlet weak var label: NSTextField!
var labelContent : String?
var delegate: InitialViewController? // Must be InitialViewController
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
label.stringValue = labelContent ?? "empty"
}
func popoverDidClose(_ notification: Notification) {
delegate?.handleClosePopover()
}
}
Hope that helps.