У меня есть приложение macOS с двумя кнопками, но они не срабатывают. Я подключил IBActions к кнопкам.
Документ
override func windowControllerDidLoadNib(_ windowController: NSWindowController) {
super.windowControllerDidLoadNib(windowController)
// user interface preparation code
guard let context = self.managedObjectContext else { fatalError("context is nil") }
mainObjectContext = context
let mainWindowController = MainWindowController(nibName: NSNib.Name(rawValue: "MainWindowController"), bundle: nil)
customView1.addSubview(mainWindowController.view)
setUpLayoutConstraints(item: mainWindowController.view, toItem: customView1)
}
func setUpLayoutConstraints(item : NSView, toItem: NSView)
{
item.translatesAutoresizingMaskIntoConstraints = false
let sourceListLayoutConstraints = [
NSLayoutConstraint(item: item, attribute: .left, relatedBy: .equal, toItem: toItem, attribute: .left, multiplier: 1, constant: 0),
NSLayoutConstraint(item: item, attribute: .right, relatedBy: .equal, toItem: toItem, attribute: .right, multiplier: 1, constant: 0),
NSLayoutConstraint(item: item, attribute: .top, relatedBy: .equal, toItem: toItem, attribute: .top, multiplier: 1, constant: 0),
NSLayoutConstraint(item: item, attribute: .bottom, relatedBy: .equal, toItem: toItem, attribute: .bottom, multiplier: 1, constant: 0)]
NSLayoutConstraint.activate(sourceListLayoutConstraints)
}
и MainWindowController
класс MainWindowController: NSViewController {
@objc var managedObjectContext: NSManagedObjectContext = mainObjectContext
@objc dynamic var customSortDescriptors = [NSSortDescriptor(key: "name", ascending: true, selector: #selector(NSString.localizedStandardCompare(_:)))];
@IBOutlet weak var textFiled: NSTextField!
override func viewDidLoad() {
super.viewDidLoad()
// Do view setup here.
print("hello")
textFiled.stringValue = "hello"
}
@IBAction func actionAddNew(_ sender: Any) {
print("add")
textFiled.stringValue = "add"
}
@IBAction func actionRemove(_ sender: Any) {
print("remove")
textFiled.stringValue = "remove"
}
}
все перепробовал не знаю что делать
Я точно что-то забыл в другом приложении NSPersistentDocument нет проблем
https://www.dropbox.com/s/qlww3hgii7wamup/CoreDataDragDropSwift2.zip?dl=0
mainWindowController
освобождается в концеwindowControllerDidLoadNib
. - person Willeke   schedule 18.01.2018