我正在尝试将组添加到我的NSTableView中。我发现这个功能:
func tableView(tableView: NSTableView, isGroupRow row: Int) -> Bool
{
if (row == 5)
{
return true;
}
return false;
}效果很好。第5行是后面的一个组。但我不知道该怎么增加一个标题呢?
我使用的是自定义视图:
func tableView(tableView: NSTableView, viewForTableColumn tableColumn: NSTableColumn?, row: Int) -> NSView?
{
if (row == 5)
{
??????
}
let result : CellViewCustom = tableView.makeViewWithIdentifier(tableColumn!.identifier, owner: self) as! CellViewCustom
...
return result
}但是在第5行,上面写着tableColumn == nil
如何向组标题添加文本?
发布于 2016-08-24 14:23:50
与iOS不同,NSTableView的组单元在(非嵌套的)数据源数组中是“内联”的。
简单示例
Item、title和isGroup的自定义结构isGroup。所有title不是空的实例都是组行。
结构项目{ let name,title : String let isGroup : Bool init(名称: String,title : String = "") { self.name = name self.title = title self.isGroup = !title.isEmpty }isGroupRow中,只返回属性值
func tableView(tableView: NSTableView,isGroupRow行: Int) -> Bool {返回itemsrow.isGroup }viewForTableColumn中,为组和表行创建两个不同的视图
func tableView(tableView: NSTableView,viewForTableColumn tableColumn: NSTableColumn?,row: Int) -> NSView?{如果item.isGroup { let groupCell = tableView.makeViewWithIdentifier("GroupCell",owner:self) as!NSTableCellView groupCell.textField!.stringValue = item.title返回单元}.stringValue{让单元格=groupCell.textField所有者: self) as!CellViewCustom ...返回单元}https://stackoverflow.com/questions/39124756
复制相似问题