Drop on NSTableView Behavior - cocoa

I have an NSTableView and I have successfully implemented both tableView:validateDrop:proposedRow:proposedDropOperation: and tableView:acceptDrop:row:dropOperation:.
I don't need tableView:writeRowsWithIndexes:toPasteboard: because that's for dragging objects out of the NSTableView.
Now, the problem is that I want it to behave kind of iTunes-like. In iTunes 9.x (I don't remember it for the previous versions) you have an NSTableView (the playlist) and when you drag a file over it you get this blue focus inside the NSTableView (maybe it's the NSScrollView?) and you don't have the blue horizontal line that indicates where you're going to insert an object. So basically I would like:
No blue horizontal insert line
between rows when hovering a file
over the NSTableView.
The blue focus inside the NSTableView
(or NSScrollView).
Any help would be greatly appreciated so thank you in advance.

From the NSTableView reference:
- (void)setDropRow:(NSInteger)row dropOperation:(NSTableViewDropOperation)operation
....
"Passing a value of –1 for row, and NSTableViewDropOn as the operation causes the entire table view to be highlighted rather than a specific row. This is useful if the data displayed by the receiver does not allow the user to drop items at a specific row location"

Related

How to change the colour of selected row in NSTableView?

I have a view based NSTableView where each row is NSView. When user clicks on any row it should have rounded corner and colour.
I need to achieve something like -
Here trash is selected row.
I found one solution here, But it is NSTableRowView Based solution, not NSView based.
Thanks for your help.
Why is the NSTableRowView solution a problem? In view-based tables, each row consists of two main views:
An NSTableCellView. Since table views can have multiple columns, each row contains an NSTableCellView for each column in the table.
An NSTableRowView. This is displayed behind the NSTableCellViews for each row in the table. By default, this is the view which displays the blue background.
There's a good diagram showing this in Apple's documentation.
As such, creating your own NSTableRowView which draws the red/orange background would be a good way of achieving what you want as it sits behind the NSTableCellViews for the row. You can set these rows up and return them in the - tableView:rowViewForRow: NSTableViewDelegate method.

Cells don't resize when user resizes NSTableViews columns?

I have found that the text in a table view doesn't grow when the user resizes the column. (Or for that matter shrink if he shrinks the column, because the truncation ellipses then vanish.) Having gathered that this is something to do with constraints, my solution has been to uncheck Use Auto Layout (in the xib's file inspector). Not a big deal, but it comes just when I was beginning to think I might have mastered Autolayout.
Is that really the only way to do this?
The table is view-based, and gets its data from Core Data via an array controller. The text is displayed in an NSTextField.
It is as you have found out yourself.
If you want to know/learn more about NSTableview-behavior search for "TableViewVariableRowHeights" and "TableViewLinks" in Apples documentation and download the samples.
This question appears to be answered in:
How to Expand NSTableCellView Width When Resizing Column in NSTableView
summary: add horizontal constraints to the table view cell
see the link for screenshots

mouseOver for NSTableView

I have NSTableView in my application and i have added the hovering effect for the rows by using HoverTableDemo.
I can get the hovering effect only for one row in my table.
It is not apply for the whole table.
How can i get Hovering effect for full table.
Can any body have any idea please revert me.
Take a look: https://stackoverflow.com/a/464828/1758762
You're on the right track with -mouseEntered: and -mouseExited:.
Look into NSView's -addTrackingRect:owner:userData:assumeInside: and -removeTrackingRect: methods.
I can get the hovering effect only for one row in my table.
You can either set up your tableView to create trackingRects for every row that's in there whenever the contents of the tableView change, or alternatively, set up/update one tracking area on the entire tableView whenever -tile or another layout related method is called.

Hover effect issue in NSTableView

I have a view based NSTableView in my application and I have added the hovering effect for the rows using the implementation in HoverTableDemo. I can get the hovering effect when the mouse is over a row without a problem , however when the tableview is scrolled down sometimes it leaves highlighting effect on the top cells when the table view is scrolled up again. I think this is due to NSTableView reuses the cell. I highlight the row by overriding the
- (void)drawBackgroundInRect:(NSRect)dirtyRect
method in NSTableRowView. Could someone point me to the right direction to solve this issue ?
Thanks in advance .
I think it is because the mouseExit event does not get called on scrolling and hence the background is not reset.

NSOutlineView badges in NSSplitView

I have an NSOutlineView which I draw badge numbers to the right side of cells using drawAtPoint:, NSAttributedString, and of course NSBezierPath. My problem exists when resizing of the outline view occurs when within a subview of an NSSplitView. The badges move along with the resize to the left or right. When they get to the text of the cells themselves they do not stop or truncate the text under them. It just flies right over.
Is there a way to have the cell recognize the custom drawn view next to it and truncate text accordingly? I have tried the solution PXSourceList already, but that did not help either.
"PXSourceList solution" working good. You subclass NSOutlineView and overload frameOfCellAtColumn for this particular task. At this function you need to decrease width of cellFrame, returned from super call, by the width of your badge plus padding.

Resources