Objective C-OSX How to change color of NSTableViewCell when selecting? - objective-c

there are 3 cell in my table view
my table is view base table
my requirement is when i select any cell(click on any row) text color and background color of that(selected cell) table view cell change

A naive solution could be using NSTableViewDelegate declared as tableViewSelectionDidChange:. Inside it use the property selectedRowIndexes, which will provide the currently selected rows. Then customize those cell as you want (changing the background color or whatever else).
NB :: don't forget to clear the cell's which are not in the selectedRowIndexes, otherwise deselcting won't change their state

Related

Design tableViewCell( overlaps table view cell)

How to design this table view cell..
Cell overlaps the another cell.
Please help me
Set the y offset of the pictureImageview to be negative i.e -50.0f or so, the image will appear as starting from the cell above.
I just tried AppleDelegate's solution but didn't work, because the top of every image is cut, maybe because it is beyond the cells bounds, even with clear color for background.
A different approach would be to believe that it's just a visual effect, and cells are not overlapping. This is possible by giving a different height for every cell with next code :
- (CGFloat)tableView : (UITableView *) tableView
heightForRowAtIndexPath : (NSIndexPath *) indexPath {
// RETURN A DIFFERENT HEIGHT FOR EVERY CELL DEPENDING ON INDEXPATH,
// INCREASING IT GRADUALLY.
}
In the next image, the black lines look like cells' top border, but maybe that's the effect, and the real limit is the red line :
Thinking this way, only the first cell requires a special treatment for the green titles.
Try setting constraints in storyboard and then keep the UIImageView's size/frame of image same when the image is set to UIImageView. Good Luck!

NSTableView selected row highlight

I have a NSTableView with two columns, one is NSButtonCell and the other is a NSTextFieldCell. The text in NSTextFieldCell cannot be edited but the user can select a part of the text and make it bold. The current implementation is to allow them to do a double click and select a part of the text. The problem is, once the user is done bolding, the highlight color at selected row still persists.
The NSTableView usually has variable number of rows each time. I cannot do SelectRow as false as I need to be able to select the row. I also need to support 10.5.8 so I cannot set - NSTableViewSelectionHighlightStyle as None.
My application is a Cocoa application, which needs to run on 10.5.8, 10.6 and 10.7.
You can try setting the selected row as false. NSTableView has a method deselectRow. After bolding is done, you can deselect the row.

Get cell title from table view

I have a custom table view and each cell has a title and a button. When the user clicks on the button, I need the title of that cell to appear on another view. How do I get this?
It's not very tough here are the 2 solutions:
When you are creating the cell, assign tag to the label you want to get the title value (or text value)
second option is:
If you want to get the title at the didselect select method just get the cell from the table view with the help of indexpPath.row and then extract the label and it's text. You can assign the tag in the custom cell design and then extract it from cell (once you get the cell).

How to add a checkbox in front of folder tree in finder with Mac?

I want to change a outline view , and add checkbox cell in front of node , and the node have a icon and how to add checkbox in head of the icon?
Download the DragNDropOutlineView sample code from Apple and have a look. It contains all the features you're looking for.
As for adding cells, think of it more in terms of adding columns (a column is designed to hold one cell of a single type). If you want more controls in each row, add a new column and set its cell type. Both of these actions can be performed easily in Interface Builder. You can select the table and increase its column count by one (a new column will appear), move the column where you want it (to the beginning), and drag a checkbox-configured button cell (there's a checkbox cell in the IB palette) into the body of the column and its "data cell" prototype will be set. That's it. Just wire it up as you normally would (NSTableViewDataSource or Cocoa Bindings) and you're done.

How do you keep text from wrapping in an NSTableView using NSAttributedString

I have an NSTableView that has 2 columns, one for an icon and the other for two lines of text. In the second column, the text column, I have some larger text that is for the name of an item. Then I have a new line and some smaller text that describes the state of the item.
When the name becomes so large that it doesn't fit on one line it wraps (or when you shrink the window down so small that it causes the names to not fit on a single line).
row1===============
| image | some name |
| image | idle |
row2================
| image | some name really long name | <- this gets wrapped pushing 'idle' out of the view
| image | idle |
===================
My question is, how could I keep the text from wrapping and just have the NSTableView display a horizontal scroll-bar once the name is too large to fit?
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).