我有NSTableView。如果"Row size style: Custom“(或small等):
但如果为if "Row size style: Automatic“(我想动态调整行高)
创建单元格的代码:
extension ViewController: NSTableViewDelegate {
func tableView(_ tableView: NSTableView, viewFor tableColumn: NSTableColumn?, row: Int) -> NSView? {
let currentOption = options[row] //options is Array of dictionaries
if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "short") {
let cellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "shortCell")
guard let cellView = tableView.makeView(withIdentifier: cellIdentifier, owner: self) as? NSTableCellView else { return nil }
cellView.textField?.stringValue = currentOption["short"]!
print(cellView.fittingSize.height)
return cellView
} else if tableColumn?.identifier == NSUserInterfaceItemIdentifier(rawValue: "long") {
let cellIdentifier = NSUserInterfaceItemIdentifier(rawValue: "longCell")
guard let cellView = tableView.makeView(withIdentifier: cellIdentifier, owner: self) as? NSTableCellView else { return nil }
cellView.textField?.stringValue = currentOption["long"]!
return cellView
}
return nil
}
}
发布于 2019-12-05 16:29:32
确保你的自动布局有一个顶部和底部约束。
例如,在垂直方向上使用object1、object2、object3,确保对象1固定在superview的安全区域/顶部,并将object3固定到superview的安全区域/底部。
发布于 2019-12-06 00:45:09
你有自动布局问题。正确检查您的约束。
https://stackoverflow.com/questions/59190883
复制相似问题