NSTableview row height

Hi

As I understand, it's possible to vary the row-height of the table row so that large amount of text fits in the the TextView. Somehow I can't seem to get it to work.

Is it possible to provide detailed steps/screenshots ?


Thanaks for all the help

Answered by Claude31 in 397404022

Sorry, I should have guessed as we are in Cocoa forum.


In Cocoa, you have

optional func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat


Seems that you'll find more details in WWDC 2015

WWDC video "Mysteries of Auto Layout, Part 1", mystery #4, "Self-Sizing Table View Cells".

https://developer.apple.com/videos/play/wwdc2015/218/

View all, but self sizing table view cell is @24'

Essentially, you have to do is set a constrainst fro the text to the top and to bottom of cell.


May read also this old post

https://forums.developer.apple.com/thread/3734

Can you show the code you have so far and what does not work ?


I assume you are in Swift (not SwiftUI).


Essentially, you should either :


Add in viewWillAppear:

mytableView.estimatedRowHeight = 64.0
mytableView.rowHeight = UITableView.automaticDimension


or use the delegate func:

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
  return UITableView.automaticDimension
}

func tableView(_ tableView: UITableView, estimatedHeightForRowAt indexPath: IndexPath) -> CGFloat {
  return 64.0     // A standard height
}



Have a look here for much more details.

https://stackoverflow.com/questions/53518007/change-row-height-in-tableview-swift


And tell if you cannot make it work.

Hi Claude

This is ideed for Swift. But for Cocoa not UIKit.

So far, I've set NSTableView's Row-Size-Style to "Automatic (Auto Layout)". But not able to figure out what to do next?


Any help is really appreciated.

Accepted Answer

Sorry, I should have guessed as we are in Cocoa forum.


In Cocoa, you have

optional func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat


Seems that you'll find more details in WWDC 2015

WWDC video "Mysteries of Auto Layout, Part 1", mystery #4, "Self-Sizing Table View Cells".

https://developer.apple.com/videos/play/wwdc2015/218/

View all, but self sizing table view cell is @24'

Essentially, you have to do is set a constrainst fro the text to the top and to bottom of cell.


May read also this old post

https://forums.developer.apple.com/thread/3734

Hi Claude

Thanks, WWDC Video was good in proving the contraints that need to be set.

NSTableview row height
 
 
Q