My NSTableView has variable height rows. The rows correctly resize after an edit of a cell has been completed, and during/after resizing the column/table. The Row also correctly resizes while a user is typing into the text cell.
However, the cell itself does NOT resize during editing to match the height of the row. Does anyone have any ideas on this? In this screenshot one end-edit has occurred already (which is why the text area is larger than 1 line) but there is currently enough text in the cell to account for about 5 lines, thus the height of the row is not matching what should be displayed.
Both the textview and the cell have to have their autoresize set if you want them to automatically scale.
It looks like the cells in the Tag Name column are properly set to resize but that either the cell or the textview in the value column has not been. Check the sittings in Interface Builder.
Related
I am trying to build a screen similar to twitter/instagram profile page where there is a header section and below that scrollable content.
I have a view controller which has a table view. I wanted to include a header view on top of the table cells. So i dragged and dropped a "View" just above my cell and it works fine. Now i have a label inside this header view and i want the label height and UI view height to adjust automaticlly based on the content length of the label. (If the content is a long string, the number of lines of label should automatically increase and the container view(headerview)'s height should increased based on it's content items property.
I tried to set auto layout on the table(top left right and bottom to the container view(headerview). But then the label is shown in single line, truncated at the very right corner. If i remove the bottom constraint from my constraints, the label appear in multiple lines, but the container view(headerview)'s height is not increased, thus producing an overlap of the label on top of the table below that.
I have the number of lines property set to 0 for the label.
Can anyone share some ideas how to do this ? I am using Xcode 7 and swift 2
There are several approaches for what you want to accomplish. If you do not care if the header scrolls with the cells, the easiest way is to do something like this:
----------------
Header
Label
TableView
----------------
You should pin your header Top,Right,Left.
You should pin your tableView Right,Bottom,Left.
You should pin Header.bottom = TableView.top.
You should pin your Label 4 sides to it's superview(Header).
Set Label numberOfLines = 0
If your header has a fixed width, the label will automatically inherit that width, and setting numberOfLines=0 (a.k.a unlimited number of lines) will make your label increase it's height. Because your label is pinned to it's superView by it's 4 sides (and the header has no fixed height), your header must increase it's height to match the label height.
Hope it helps!!
Is it possible to set up a NSTableView with e.g. 4 columns in IB to allow just one column to resize when the table grows?
So far I couldn't achieve this with neither Resizing: Autoresizes or decreasing content hugging value for the TableCellView in the column that should be the only one that grows when the table is resized.
Is there any way to convince a particular column - not just the last one - to just 'let go' and resize with its NSTableView..?
In the xib, go to each column object and in the column object's attribute inspector set resizing to: None. Set resizing on the column you want to 'let go' to: Autoresizes with Table.
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.
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.
In my application I have taken a table view and displaying some NSString objects within it. User can also edit any row within it.
When I do not change color of NSTextFieldCell in NSTableColumn in IB, it shows default display property of table view ie. when a row is selected, text of selected row starts appearing white, but when I change it to some other color, say blue, then it starts appearing like this:
To resolve this problem I tried to set text color of cell in selected row as white in table delegate method: tableView:willDisplayCell:forTableColumn:row:, but it caused another problem- text remained white when edited, thus it became difficult for user to identify text entered:
Can anyone suggest me some suitable solution to resolve it?
Thanks,
Miraaj
Test whether the cell is highlighted. If it is, set its text color to [NSColor alternateSelectedControlTextColor]. If not, set it to blue (or [NSColor controlTextColor] for the regular text color).