Hello Claude31, thanks for your answer.
In the link that you posted in one of the images there is a Received Actions in the Storyboard called dismissController:.
In my storyboard I did not find this action, I have the followings actions:
performClick:
print:
takeDoubleValueFrom:
takeFloatValueFrom:
takeIntValueFrom:
takeObjecttValueFrom:
takeStringValueFrom:
The segue is declared in the Viewcontoller , not in the button. ( I drag from Viewcontoller to ShareOptionsViewController)
The project has only the WindowController that comes with the Storyboard, for window content it has ViewController and there is other NSViewController called ShareOptionsViewController.
This is the code I am using:
I can see that the delegate methods are called, but the viewController do not dismiss.
import Cocoa
import CloudKit
class ViewController: NSViewController {
var shareOptionsViewController : ShareOptionsViewController!
enum SegueIdentifier : String {
case segueToShareOptionsViewController
}
@IBAction func showShareOptionsViewController(_ sender: Any) {
performSegue(withIdentifier: SegueIdentifier.segueToShareOptionsViewController.rawValue, sender: self)
}
override func viewDidLoad() {
super.viewDidLoad()
}
override func prepare(for segue: NSStoryboardSegue, sender: Any?) {
print("\(type(of: self)) \(#function)")
guard let identifier = segue.identifier else { fatalError("Can not get segue.identifier" ) }
guard let segueIdentifier = SegueIdentifier(rawValue: identifier) else { fatalError("Can not get segueIdentifier") }
switch segueIdentifier{
case .segueToShareOptionsViewController:
if let shareOptionsViewController = segue.destinationController as? ShareOptionsViewController{
self.shareOptionsViewController = shareOptionsViewController
self.shareOptionsViewController.delegate = self
let frameSize = view.frame.size
self.shareOptionsViewController.view.frame.size.width = frameSize.width / 2
self.shareOptionsViewController.view.frame.size.height = frameSize.height / 2
// self.shareOptionsViewController.view.animator().setFrameSize(frameSize)
}
}
}
}
extension ViewController : ShareOptionsViewControllerDelegate{
func dismissShareOptionsViewController(){
print("\(type(of: self)) \(#function)")
// dismissViewController(shareOptionsViewController) // 'dismissViewController' has been renamed to 'dismiss(_:)'
// dismissController(shareOptionsViewController) // 'dismissController' has been renamed to 'dismiss(_:)'
dismiss(shareOptionsViewController)
}
func share(sharingPermissionOptions options: NSSharingService.CloudKitOptions){
print("\(type(of: self)) \(#function)")
print("options.contains(.standard): \(options.contains(.standard))")
print("options.contains(.allowPublic): \(options.contains(.allowPublic))")
print("options.contains(.allowPrivate): \(options.contains(.allowPrivate))")
print("options.contains(.allowReadOnly): \(options.contains(.allowReadOnly))")
print("options.contains(.allowReadWrite): \(options.contains(.allowReadWrite))")
// dismissViewController(shareOptionsViewController) // 'dismissViewController' has been renamed to 'dismiss(_:)'
//dismissController(shareOptionsViewController) // 'dismissController' has been renamed to 'dismiss(_:)'
dismiss(shareOptionsViewController)
}
}
import Cocoa
import CloudKit
protocol ShareOptionsViewControllerDelegate : AnyObject {
func share(sharingPermissionOptions: NSSharingService.CloudKitOptions)
func dismissShareOptionsViewController()
}
class ShareOptionsViewController: NSViewController {
weak var delegate : ShareOptionsViewControllerDelegate?
@IBAction func sharePublicReadOnly(_ sender: Any) {
delegate?.share(sharingPermissionOptions:[NSSharingService.CloudKitOptions.allowPublic, NSSharingService.CloudKitOptions.allowReadOnly])
}
@IBAction func sharePublicReadWritte(_ sender: Any) {
delegate?.share(sharingPermissionOptions:[NSSharingService.CloudKitOptions.allowPublic, NSSharingService.CloudKitOptions.allowReadWrite])
}
@IBAction func sharePrivateReadOnly(_ sender: Any) {
delegate?.share(sharingPermissionOptions:[NSSharingService.CloudKitOptions.allowPrivate, NSSharingService.CloudKitOptions.allowReadOnly])
}
@IBAction func sharePrivateReadWritte(_ sender: Any) {
delegate?.share(sharingPermissionOptions:[NSSharingService.CloudKitOptions.allowPrivate, NSSharingService.CloudKitOptions.allowReadWrite])
}
@IBAction func cancel(_ sender: Any) {
delegate?.dismissShareOptionsViewController()
}
override func viewDidLoad() {
super.viewDidLoad()
print("\(type(of: self)) \(#function)")
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.yellow.cgColor
}
}