View based NSTableView and row heights - macos

I'm beginning to try and build an OSX app.
I'm using NSTableView with it set as view-based, however I want the rows to wrap properly (so all of the text in each is shown at once) however I can't seem to find out how do to this.
Using the rowHeight delegate method seems to point to cell-based NSTableViews so I don't know if I'm doing that right or not.

First select NSTableView and then Size Inspector and set row height:
and then select table cell view's which you want change:
And if you want then you can move or resize your table view cell if you want.

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.

View based NSTableView with each view contains 3 labels with should resize based on Text

I need to create a view based tableview in Popover as specified below:
Tableview should be placed in Popover(Popover height should be same as tableview).
Each row should contain a view.
Each row view will contain 3 labels.
Labels should be auto re sizable based on its text height.
Based on 3 labels height, Cell row height should resize.
Based on all cell rows, tableview height should resize.
Based on tableview height, Popover should resize.
I have done this in a static format, but i need to do it in more dynamic format(in future i should be able to add more rows using same classes and methods).
Main problem i am facing is, i am unable calculate the size of cell view in tableView:heigthOfRow: since i don't know the text of labels in this point of time.
So i just created tableview cells in loadView itself and saved in array, and fetching from array in tableview delegate methods. But i think this is wrong way of doing so.
Note: All data to tableview will be given while loading the view itself. Labels are not editable.
Cocoa system resizes the subviews based on superview ,I think scenario that you are looking for is to resize super view based on subview size.
Following 2 solutions i can suggest right awyay,
1.You can choose to post notification upon size change in each subview and make immediate superview observe that.
2.Use globals for size of each subview in your case 3 labels, and have an API to calculate finalRect in your view of view based table view.
Hope this helps:) have a nice day.

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.

UITableViewCell: Custom Row Height for prototype cell

In my storyboard file I am designing multiple prototype cells in a UITableView. Each cell has its own unique Cell Identifier.
Depending on the section and the row I dequeue one of the prototype cells in method - tableView:cellForRowAtIndexPath:
For most of the prototype cells I have not changed the Row Height. On my storyboard, their height seems to be determined by the property 'Row Height' under 'Size Inspector' of UITableView.
For one prototype cell I have changed the height through the property 'Row Height' under 'Size Inspector' of the specific UITableViewCell. The checkbox 'Custom' is also checked.
On my storyboard this seem to work well. But during runtime when my cells are being dequeued and added to the TableView, all cells get the default row height.
Now, I am aware of the method tableView:heightForRowAtIndexPath: which is being mentioned in other posts but it seems a little odd to use as I am setting a custom row height in my storyboard already.
Does somebody know why this property is not working? Is this property maybe mend to be used in different situations?
Thanks
If you want to use Interface Builder in Xcode 5 to change the height of the rows in a table view without code you can do it in two places:
Select the table view, show the Size inspector and type it in
Row Height, in the Table View Size section.
Select the prototype cell, show the Size inspector, check Custom in the Table View Size section and type the row height in the associate text field.
Could it be that you're using the second method? Try to use the first method to set the default height of all the rows in the table view and the second to tell Interface Builder about the exceptions.
heightForRowAtIndexPath is called (for each row of the table) before the cells are displayed, i.e. before cellForRowAtIndexPath is called. That is necessary to compute the layout of the underlying scrollview, the scroll indicators etc.

Drop on NSTableView Behavior

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"

Resources