How to save text from packaging in NSTableView using NSAttributedString

I have an NSTableView that has 2 columns, one for the icon, and the other for two lines of text. In the second column of the text column, I have a larger text intended for the element name. Then I have a new line and a little text describing the state of the element.

When a name becomes so large that it does not fit on one line, it wraps (or when you shrink a window so small that it prevents names from fitting on one line).

row1 ================
| image | some names |
| image | idle |
row2 =================
| image | some name really long name | <- this is wrapped by clicking "inaction" from the view
| image | idle |
=====================

My question is, how can I keep the text from wrapping and just show the NSTableView a horizontal scrollbar when the name is too big to fit?

+5
source share
1 answer

Cocoa NSScrollView, , , , , NSTableView . (, ) , , , , .

NSTextFieldCell, "Truncates" IB "Wraps".

NSCell, ( , ), NSParagraphStyle, , NSParagraphStyleAttributeName NSAttributedString.

:

NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedStr
 addAttribute:NSParagraphStyleAttributeName
 value:paragraphStyle
 range:NSMakeRange(0,[attributedStr length])];

, - , :

, , .

- , NSCell, , -drawWithExpansionFrame:inView: -expansionFrameWithFrame:inView: . , NO NSTableViewDelegate -tableView:shouldShowCellExpansionForTableColumn:row: ( ).

?

(, , , ), , , , , NSTableViewDelegate, , -cellSize ( , ).

+12

All Articles