我努力學習斯威夫特,但我似乎在這(誠然,可能是很簡單的)問題已經得到陷入 - 錯誤如下:爲什麼該操作無法連接到目標類NSViewController?
Could not connect action, target class NSViewController does not respond to -(encbutton/decbutton)
這裏是我的代碼。我在Storyboard中設計我的界面並通過@IB(Outlet/Action)
將它連接到代碼。
// ViewController.swift
import Cocoa
import Foundation
class TabViewController: NSTabViewController {
// This has been changed from NSViewController to NSTabViewController as I have replaced the initial single-view with a two-tab-view.
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override var representedObject: AnyObject? {
didSet {
// Update the view, if already loaded.
}
}
}
public class EncViewController: NSViewController {
// This is for the first tab, encrypt
@IBOutlet var encdirfield: NSTextField!
@IBOutlet var encpassfield: NSSecureTextField!
@IBOutlet var enclogfield: NSTextField!
@IBOutlet var encbutton: NSButton!
@IBAction func startenc(sender: NSButton) { // here's the problem. the function isn't triggered when the button is pressed
// get values
encdir = encdirfield.stringValue
encpass = encpassfield.stringValue
tarcrypt.enc();
// this is an function that leads to an NSTask that runs a binary I wrote (not related).
// definitely not the cause of the problem because running it independently works fine
}
}
public class DecViewController: NSViewController {
// and this is for the second tab, decrypt
@IBOutlet var decdirfield: NSTextField!
@IBOutlet var decpassfield: NSSecureTextField!
@IBOutlet var declogfield: NSTextField!
@IBOutlet var decbutton: NSButton!
@IBAction func startdec(sender: NSButton) { // here's the same problem, again. the function isn't triggered when the button is pressed
// get values
encdir = encdirfield.stringValue
encpass = encpassfield.stringValue
tarcrypt.dec();
// this is an function that leads to an NSTask that runs a binary I wrote (not related).
// definitely not the cause of the problem because running it independently works fine
}
}
出於某種原因,在繪製場景以及NSButton時,會生成如上所示的錯誤消息。是什麼導致了錯誤,我該如何解決?