NSTableView: Avoid Blue Header when Sorting Table Column - objective-c

when I click on the header of an NSTableView column, the header gets blue and the little grey arrow shows up. How do I avoid the blue selection and the arrow (but keeping the sorting itself)?
As an example for what I want: In Xcode click on the 'Groups & Files' header.
Thank your for any help!

If you are working with a multi-column table you should never try to disable the arrow and highlighting, how else is the user going to know what the sorting is... If you are working with a single column table (in a source list manner) then lose the header and go with the source list style for the table. Before deciding to override standard behavior you should read the Apple interface guidelines and consider if you really need override those behaviors. For the record Xcode's Groups & Files doesn't sort and that is why it doesn't turn blue or get an arrow.

You can control what shows in the indicator with NSTableView's instance method "setIndicatorImage:inTableColumn:". I don't know if there's a way to just change the highlight as easily.
You can get more control, including the highlight if you subclass NSTableViewCell and override the methods "drawSortIndicatorWithFrame:inView:ascending:priority:" and/or "highlight:withFrame:inView" to control both the indicator element and highlighting. Then you can use this in your table column like so:
NSTableHeaderCell *headerCell = [[[CustomHeaderCell alloc] init] autorelease];
[tableColumn setHeaderCell:headerCell];

Related

How can I make command-A select all the NSTextView text in rows in an NSTableView?

So if I have an NSView based tableview and inside the views are NSTextViews which are non-editable but selectable...
how can I get that nice functionality of command-A selects all the text? I don't mean row selection. I have row selection disabled for the tableview. I mean highlighting the text in blue so you can copy it to your clipboard. But not just 1 NSTextView's text from one row, all of them from all the rows.
And in addition to command-A click and drag should do this too. But out of the box it seems I can only select one row's text. Here is video showing problem:
https://dl.dropboxusercontent.com/u/2510380/table.mov
(i keep clicking and dragging but can't highlight text on the next row)
here are two mac apps (skype and gabble) that do this:
https://dl.dropboxusercontent.com/u/2510380/skype.mov
and
https://dl.dropboxusercontent.com/u/2510380/gabble.mov
Assuming they are NOT using WebViews with just HTML inside, how do you get this control over the clipboard? i.e. in Skype you select the text and only the conversation is highlighted, not the timestamp of each message. Also the text copied to the clipboard is formatted very nicely. Can you point me in the right direction to reverse engineer skype?
Unfortunately there's no way to do this easily. This is because only ONE control can be the first responder at a time. This means that, though you can have selection in multiple text views, there are several problems:
Only one text view's text will actually be highlighted with the "live" highlight color; the others will have the gray highlight of non-focused controls.
Copy commands will only apply to the first responder text view.
Drag session starts will be initiated from the control the mouse was actually pointing at (irrespective of first responder) and will only drag that control's text.
In a view-based table view, the controls may not even "exist" for a row not currently displayed, so it'll never get the message unless you forcibly create each row, which could be costly for a large table.
Knowing all this, you might be able to "fake it" by having your controller be complicit in a text view and table view subclass's special handling of a select-all message when it's first responder. On receiving this message, the text view subclass can call super then notify the controller (to get its default behavior AND to let you know it happened), at which point the controller can turn around and send the command to all (existing) text views. Highlighting can be spoofed by overriding the text view's drawing and a drag initiation could defer to a delegate (the controller), which would handle writing ALL the strings from your model to the pasteboard (not even touching the text views in possibly-nonexistent row views). The table view subclass would simply pass the same select-all message to the controller without calling super (and even forcibly making sure nothing is selected before returning for good measure).
I hope this helps. If I've forgotten any of your requirements, let me know.
Try like this:-
First create button programatically then write this code after you create button and also write this code in your load method or awakefromnib method.
NSButton *Buttn=// alloc initwithframe;
[Buttn setKeyEquivalentModifierMask:
NSCommandKeyMask];
[Buttn setKeyEquivalent:#"A"];
[Buttn
setAction:#selector(yourmeth:)];
[Buttn setTarget:self];
// now when you press cmd a write
below code in action method
- (void)selectRowIndexes:(NSIndexSet
*)indexes byExtendingSelection:
(BOOL)extend

NSTableView group row text field selection

I want to make a custom text selection in my table view.
I found this awesome answer on how to set the colors, fonts, etc. of the cells.
However, there is one issue.
It does not work for group rows. I see that the method gets invoked, but I think the style gets overwritten somewhere in either the NSTableCellView, or in the NSTableView class.
How can I fix this?
EDIT
It's a view based NSTableView

Is there a way to display a different small image (icon) for each row of a NSTableColumn?

Is there a way to display a different small image (icon) for each row of a NSTableColumn ?
I don't necessarily need to add a new column for it, I was wondering if I can just add the icon in front of the text of each row.
I know there is the method: - (void)setDataCell:(NSCell *)aCell . However this method seems to use the same cell for all rows, which is not what I want.
Is there a solution to this problem which doesn't require to subclass the NSTableColumn ? If not, what should I subclass ?
thanks
Make the cell for the column in question an NSImageCell. You can do this in Interface Builder by dragging an "Image Cell" from the object library onto the column. Then select the column and you'll be able to bind to an image source via one of the Data, Value, Value Path, or Valueurl bindings. Which one you choose depends on whether the source property in your model returns NSData, NSImage, NSString path, or NSURL url, respectively. See the documentation on NSImageCell bindings for more complete information.
Cells are the same for each row, because they're a lightweight class used as a performance optimization for drawing. That doesn't mean that each row has to use the cell to draw the same image though, any more than the text columns' cells have to draw the same string for each row.
If you really need the image to be in the same column as text, you'll have to do something more like duDE explains. Off the top of my head, I believe bindings should be still possible in this case, but you'll have to write more code to make that work. Rather than do that, I would probably switch to using a view based NSTableView, which makes putting multiple views in a single column/row easy, and will let you continue to use bindings without any extra work.
EDIT: duDE's answer was deleted, but to summarize, it suggested creating a custom NSCell subclass that would draw both an image and text.

NSOutlineView elements remain hopelessly undraggable

I have a program with a NSOutlineView (that supports single selection only) from which I'd like to be able to drag elements. These elements should either be received as text or files: for instance, dropping the item on a TextEdit window should put text, but dropping the item on the Finder should create a file. I don't want anything to be dropped over my outline view, even it it comes from itself. This seems easy enough, but for some reason, I can't get it to work.
I checked the NSOutlineView drag and drop example from Apple, and I came to implement the following methods (plus a few definitely unrelated ones):
-(BOOL)outlineView:shouldSelectItem: // I don't expect to drag unselectable items
-(NSArray*)outlineView:namesOfPromisedFilesDroppedAtDestination:forDraggedItems:
-(BOOL)outlineView:writeItems:toPasteboard:
However, when I try to drag an item from my outline view, nothing happens. Instead, it just changes the selection following the cursor.
I've put breakpoints in the two last methods, and they never get called, so their implementation is not the immediate issue.
I must be missing something really obvious here.
Also, this is not (yet) a problem, but how am I supposed to provide contents to my promised files?
I was being stupid and I implemented the methods in the delegate instead of the data source (the two are distinct in my app). Problem solved!
Are you using a custom table view cell? The result of NSCell's hitTestForEvent:inRect:ofView: determines whether a dragging operation can be initiated. It also determines whether your outlineView:writeItems:toPasteboard: should be called.
This method should return NSCellHitContentArea to initiate a drag, or NSCellHitTrackableArea to extend or change the selection.
A standard text cell returns NSCellHitContentArea when you click on the actual text of the cell, and NSCellHitTrackableArea when you click outside of the text. This produces the drag behavior you see in Finder's table view.
You can override this method and always return NSCellHitContentArea if you want all areas of the cell to initiate a drag operation.
See Hit Testing for more information.

Changing UITableCellView appearance before it is highlighted (from UITableView)

I may have taken a million wrong turns to get to this question, so I'm happy to revise if someone can spot where I went wrong.
I am trying to build a tableview that looks the same as the Contacts app. My first issue is that an entry will have both a bolded and unbolded string in a given row like "John Appleseed" or "Martin Luther King". I figured I need have two UILabels within my UITableViewCell (possible my first mistake).
All I want to do is simply add that second UILabel so instead of subclassing I just add another UILabel in UITableViewCell (possible my next mistake).
However when a row is highlighted (but not yet selected) the default UILabel text switches to white, but my ad-hoc UILabel remains black. I can only force the UILabel text to change to white in the UITableViewDelegate methods which occur AFTER the highlighting. This cause I noticeable flash of white -> black.
Now I see the UITableViewCell method 'setHighlighted:animated:' which I could override if I subclassed, but I was hoping the were another way to approach it.
Thoughts?
I think you're going to find it difficult to keep the last name proportionally spaced from the other portion of the name in a separate view, especially given that the views may be resized by the table view in a number of situations (for example, to accommodate controls when the table view is in editing mode).
It should be a lot easier to create a custom subclass of UITableViewCell and override its -drawRect: method to draw the text itself. Take a look at the UIStringDrawing category on NSString for a list of messages you can send to an instance of NSString to tell it to draw itself either at a given point, or within a given rectangle.