[英]NSTableView not working
I followed this tutorial instead of nib files, i used storyboarding. 我遵循本教程而不是nib文件,而是使用情节提要。 I have no idea what mistake i did.
我不知道我犯了什么错误。 When i run it, its just showing the 10 tableview cells, it does not displaying the values that i passed.
当我运行它时,它仅显示10个tableview单元,它不显示我传递的值。
This is the code i used -> 这是我使用的代码->
// MARK: - NSTableViewDataSource
//标记:-NSTableViewDataSource
func numberOfRowsInTableView(aTableView: NSTableView!) -> Int {
return 10
}
func tableView(tableView: NSTableView!, viewForTableColumn tableColumn: NSTableColumn!, row: Int) -> NSView! {
// 1
var cellView: NSTableCellView = tableView.makeViewWithIdentifier(tableView.identifier, owner: self) as NSTableCellView
// 2
if tableColumn.identifier == "BugColumn" {
// 3
cellView.imageView!.image = NSImage(named: "delete")!
cellView.textField!.stringValue = "Alvin"
return cellView
}
return cellView
}
override func awakeFromNib()
{
self.tableView.setDataSource(self)
self.tableView.setDelegate(self)
}
Please help me to figure out, what i missing in here.? 请帮我弄清楚,我在这里想念的是什么? Output : i am just getting the default tableView cells ten times, there are values that i given in the dataSource.
输出:我只是获得默认的tableView单元格十次,所以我在dataSource中给出了一些值。 Thanks in advance.
提前致谢。
You're using the tableView's identifier, but instead you should use the tableColumn's one: 您正在使用tableView的标识符,但是应该使用tableColumn的标识符:
var cellView: NSTableCellView = tableView.makeViewWithIdentifier(tableView.identifier, owner: self) as NSTableCellView
// ^^^^^^^^^
var cellView: NSTableCellView = tableView.makeViewWithIdentifier(tableColumn.identifier, owner: self) as NSTableCellView
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.