Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to increase the row height in NSTableView based on the text Content?

How to increase the row height in a NSTableView based on the text Content.Row height should be increased when there is more text and the row should shrink when the text is deleted.

I implemented the textDidChange notification in my subclass of NSTableView,but I did not find any method which will increase the row height. setRowHeight of NSTableView will increase the height of every row in the tableview. I would like to a variable row height.Can I have any sample code or any pointers to accomplish this.


I found the following link

http://cocoadev.com/forums/discussion/1851/calculating-row-heights

But I am not able to find any example on this!. Any example on this would be a great help for me!


Tried to implement the following deleagate

- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row

by calculating the string length,Now I am able to increase the row height ,but the NSTextFieldCell height is same. How can I increase the height of the textfield when the row height changes.

like image 780
Ram Avatar asked Dec 23 '11 12:12

Ram


1 Answers

corbin dunn gave a solution:

  • fix your autoresizing/AutoLayout coinstraints so the text view sticks to its container,
  • calculate the row height -tableView:heightOfRow: with the help of a custom NSTableCellView object.
like image 79
ctietze Avatar answered Oct 23 '22 13:10

ctietze