Scrolling in Cocoa is implemented with the NSScrollView
which is a view instead of a cell so if you really want to implement horizontal scrolling for table view cells I think you'd have to subclass the whole NSTableView
and implement the feature there. My suggestion (without knowing the specifics of your situation, of course) is that you don't do that, though, since it's nonstandard behaviour and would probably entail quite a bit of work.
Truncate Instead of Wrap
If you're using a standard NSTextFieldCell
, just select "Truncates" for its layout value in IB instead of "Wraps".
If you have a custom NSCell
where you're doing your own drawing (I assume this is the case here), you should create an NSParagraphStyle
, set its line break mode, add it as a value for the NSParagraphStyleAttributeName
key in the NSAttributedString
's text attributes dictionary.
An example:
NSMutableParagraphStyle *paragraphStyle = [[[NSMutableParagraphStyle alloc] init] autorelease];
[paragraphStyle setLineBreakMode:NSLineBreakByTruncatingTail];
[attributedStr
addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0,[attributedStr length])];
Cell Expansion Frames
If you don't want to wrap your lines of text in the table view cells, the standard method of allowing the user to see the whole text is to use cell expansion frames which are enabled by default:
Cell expansion can occur when the mouse hovers over the specified cell and the cell contents are unable to be fully displayed within the cell.
If they're not working for some reason and you're using a custom NSCell
subclass, make sure you implement -drawWithExpansionFrame:inView:
and -expansionFrameWithFrame:inView:
in your cell. Also make sure you're not returning NO
in your NSTableViewDelegate
for -tableView:shouldShowCellExpansionForTableColumn:row:
(if you have one).
Adjust Width of Whole Table View?
If what you want to do is to adjust the width of a specific column (and thus the whole table view, possibly causing the enclosing scroll view's horizontal scroll bar to appear) such that the text its cells contain would never be truncated or wrapped, you can probably do that in your NSTableViewDelegate
, for example, by calling -cellSize
for each row's cell in that column and resizing the column to the largest value (you'll want to only do this when the values change, of course).