Skip to content

Instantly share code, notes, and snippets.

@PadraigK
Last active November 14, 2019 20:48
Show Gist options
  • Save PadraigK/1286b3a738fe3b11e13b0eff73f41fd9 to your computer and use it in GitHub Desktop.
Save PadraigK/1286b3a738fe3b11e13b0eff73f41fd9 to your computer and use it in GitHub Desktop.
Adding a footer to NSTableView
import Cocoa
class TableContainerView : NSView {
let tableView : NSTableView
let footerView : NSView
init(tableView: NSTableView) {
self.tableView = tableView
var containerFrame = tableView.frame
containerFrame.size.height = containerFrame.size.height + 30
tableView.frame.origin.y = 30
footerView = NSTextField(labelWithString: "Footer")
footerView.frame.origin.y = 5
super.init(frame: containerFrame)
addSubview(footerView)
addSubview(tableView)
if let scrollView = tableView.enclosingScrollView,
let documentView = scrollView.documentView {
scrollView.scroll(NSPoint(x: 0, y: documentView.bounds.size.height))
}
}
// NSTableView checks if its enclosing scrollview's documentView has a headerView method
// and won't draw it if it doesn't.
@objc open var headerView: NSTableHeaderView? {
return tableView.headerView
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
class ViewController: NSViewController {
@IBOutlet var tableView : NSTableView!
override func viewDidLoad() {
super.viewDidLoad()
let scrollView = tableView.enclosingScrollView!
scrollView.documentView = TableContainerView(tableView: tableView)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment