Get array in TableView

Hello together,


I have a the problem, that my generated Table is empty. Has anybody an idea?


Here is the Code:



import Cocoa

class FourthViewController: NSViewController {


let Messen = [

("A"),

("B"),

("C")

]


@IBOutlet weak var table: NSTableView!

override func viewDidLoad() {

super.viewDidLoad()

table.setDelegate(self)

table.setDataSource(self)


}

override var representedObject: AnyObject? {

didSet {


}

}

}

extension FourthViewController: NSTableViewDataSource, NSTableViewDelegate {

/

func numberOfRowsInTableView(tableView: NSTableView) -> Int {

return Messen.count

}

func tableView(tableView: NSTableView!, cellForRowAtIndexPath indexPath: NSIndexPath) -> NSTableCellView {

var cell = NSTableCellView()

let(test) = Messen [indexPath.item]

cell.textField!.stringValue = test

return cell

}

}

Replies

What version of Xcode are you using?

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Xcode 7.3.1 und swift 2

You seem to be treating an NSTableView like a UIKit table view. NSTableView has no concept of a ‘cellForRowAtIndexPath’ delegate callback. Rather, for view-based tables you typically use the

tableView(_:viewForTableColumn:row:)
delegate callback. You can learn more about this in Table View Programming Guide for Mac.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"