5

Is there any way I can adjust the height of NSTextFieldCell in an NSTableView based on the amount of text in it?

In short, I want tableView:heightOfRow: to return a value according to the text in the corresponding NSTextFieldCell and keep updating every time the text increases from a pre-defined number of lines.

I can get the dynamic height the first time the table is loaded. But can't get a way of changing it when the text updates.

Thanks.

lostInTransit
  • 70,519
  • 61
  • 198
  • 274

1 Answers1

0

Sounds like you'll need to call

[NSTableView reloadDataForRowIndexes:columnIndexes:] for all the data underneath the cell you're modifying, and of course [NSTableViewDelegate tableView:heightOfRow:].

This might be a helpful related question you can refer to.

Community
  • 1
  • 1
Michael Dautermann
  • 88,797
  • 17
  • 166
  • 215
  • Thanks. But this is for static content. As I said, I can get it working the first time the data loads. But when I start editing the text in the cells, I can't get the height to be adjusted according to the text. – lostInTransit Nov 25 '11 at 12:30
  • Ewww. That sounds like a, um, interesting user interface to say the least. I can't think of any other apps off the top of my head that allow users to edit the text in an actual table view cell within a table. I'd recommend doing this in a detail view instead. – Michael Dautermann Nov 25 '11 at 12:34
  • 1
    Mike this is a Mac app (NSTableView and NSTextFieldCell), not an iOS app. The whole point behind an NSTextFieldCell is allowing user to update the content right inside the table cell. – lostInTransit Nov 25 '11 at 13:10
  • I've changed my original answer for NSTableView... but yes, I still think the UI is potentially problematic. – Michael Dautermann Nov 25 '11 at 21:36
  • 4
    @MichaelDautermann - A lot of iPhone apps do this, even the Contacts and Reminder apps from Apple, and on the Mac editing in the table cell is expected. – sosborn Nov 25 '11 at 22:59