我在名为AddContactViewController的子视图中有“按钮”
我正在另一个名为AddContactScrollViewController的ViewController中的ScrollView中显示它。
我正在为AddContactViewController中的按钮设置操作 但是,当我单击我的按钮时,什么也没发生。
这是我的IB的屏幕截图。下面是代码。
主视图控制器
子视图
import Cocoa
class AddContactScrollViewController: NSViewController {
@IBOutlet weak var scrollView: NSScrollView!
var contentView: NSView?
override func viewDidLoad() {
super.viewDidLoad()
contentView = NSView(frame: NSRect(x: 0, y: 0, width: self.view.frame.width, height: 1123))
contentView!.wantsLayer = true
contentView!.layer?.backgroundColor = NSColor.clear.cgColor
let tempVC = self.storyboard?.instantiateController(withIdentifier: NSStoryboard.SceneIdentifier(rawValue: "addAddress")) as! AddAddressViewController
vc.view.setFrameOrigin(NSPoint(x: 0, y: 0))
vc.view.setFrameSize(NSSize(width: 1200, height: 1123))
vc.view.wantsLayer = true
contentView!.addSubview(vc.view)
scrollView.documentView = contentView
// scroll to the top
if let documentView = scrollView.documentView {
documentView.scroll(NSPoint(x: 0, y: documentView.bounds.size.height))
}
}
override func viewDidAppear() {
}
}
import Cocoa
class AddContactVeiwController: NSViewController {
override func viewDidLoad() {
super.viewDidLoad()
}
@IBAction func addPhoneButtonClicked(_ sender: Any) {
print("phone button clicked")
}