Notify UITableView of changed UITableViewCell height at runtime - autolayout

I have a tableView which rows' heights are calculated dynamically using UITableViewAutomaticDimension and AutoLayout constraints from IB.
I have a label inside each cell bound to a ReactiveCocoa MutableProperty, so that it gets updated whenever that changes.
Text changes also often outgrow the existing cell and I can't seem to find a way to notify the UITableView that the height of the cell should be recalculated.
Using tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: .Automatic) or tableView.reloadData() is not an option, since it is far to invasive and can result in loops unless explicitly managed...
Is there any way to just convey the minimal information "please update the height of this UITableViewCell", without discarding the cell?
cell.setNeedsLayout() does not seem to suffice.

According to this answer, the only way to reliably resize a UITableViewCell after it's been added to the table view, and the method suggested by Apple, is to call the following two methods:
[tableView beginUpdates];
[tableView endUpdates];

Related

UICollectionView with self sizing cells uses estimatedItemSize for delete animation

I'm using UICollectionView with self sizing cells and have set the estimatedItemSize property for this to work.
When performing a delete animation however, the cells animate to their position if they were sized with the estimatedItemSize property, rather than their auto layout (actual) size.
What's worse is that our cells are variable sizes and there doesn't seem to be a method like UITableView where we can pass an estimated size per index path.
I attempted to subclass the collection view flow layout and override the initialLayoutAttributesForAppearingItemAtIndexPath(_:) and finalLayoutAttributesForDisappearingItemAtIndexPath(_:), but on inspection the superclass's return values for these methods are correct.
Does anyone know of a solution to this seemingly basic bug?

qt : expandable/collapsable listview

I hope to create a "NEW" listview like QML Exmaple with native Qt classes.
Exactly I want to make a listview which works like below.
It looks like a QML example but slightly differs. QListView has a limitation for it's layout, right? I want a hint for overcoming the problem.
You'd want to use GridView instead of ListView. That'll get you a step closer to making your UI look like what you have designed. However currently Qt Quick only supports fixed cell sizes of grid items, which means you won't be able to expand the cell size of just one item. All you can do is set up the cell size to fit the expanded item so that every grid item will take up as much space as it could possibly need. Then you can alter the dimensions of each item without worrying about fitting issues.

Flex DataGrid columns won't resize

I am having serious problems trying to resize columns in a DataGrid. I've been at it for over a day now and am at my wit's end with a headache to boot.
Essentially, I have a TabNavigator component with NavigatorContent children inside. In each one of the NavigatorContent children, I have a DataGrid to which I'm setting the width to 100% (this is needed to be able to handle resizing of the browser window). I am using the excellent filterable DataGrid from Iwo Banas as the DataGrid in each tab.
Now, I am making visible/invisible some columns in each of the DataGrids and this is working fine. However, I find that the column widths are not being set correctly. Whenever I set the column widths (using this code), all of the columns seem to be set to the correct width except for the ones that I have recently made visible and the column immediately to the left of these. The ones recently made visible are very small (though I set their width to 30) and the one to the left of these columns is very large (though I've also set its width to 30).
I think it's something to do with the life cycle of the DataGrids because the first DataGrid behaves fine. It's when I click on the other tabs that I find that the widths of the other DataGrids have not been set correctly.
However, if I "see" one of those problem DataGrids (i.e. it appears on the screen) and the code which resizes the columns runs again, the columns are correctly sized.
I have tried a number of things recommended all over the internet including the questions listed below but to no avail.
This is the code I'm using to resize the columns (taken from this answer)
public static function resizeColumn(col:DataGridColumn, size:int):void
{
var owner:* = col.mx_internal::owner
col.mx_internal::owner = null;
col.width = size;
col.mx_internal::owner = owner;
}
Any and all help would be greatly appreciated.
I have already looked at the following answers.
Flex DataGrid column width: one column to rule them all?
Flex 3 DataGrid Column Width Problem
Flex DataGrid Column Width (<-- this answer got me closest)
Unable to change the column width dynamically in flex datagrid
So, after a huge amount of head wrecking, I finally found a solution (at least to my problem, not sure if it would help anyone else but thought I'd post it here anyway as you never know what could help someone else).
I decided that since calling the resize code when the DataGrid is on screen works then I needed to just do that. So I thought of putting the resize code for the relevant DataGrid depending on the tab clicked. Not that straightforward as there didn't seem to be a straightforward way to implement a click handler for the tabs. I did a quick Google and found this solution.
Essentially, you add a click handler for each tab button by cycling through the children of the tab navigator, getting the button and adding an event listener.
Then, you do what you need to do in the handler.
Code example (slightly different to one from website):
protected function tbGridArea_creationCompleteHandler(event:FlexEvent):void
{
for ( var i:int=0; i < tbGridArea.getChildren().length; i++ )
{
var tab:Object = tbGridArea.getTabAt(i);
tab.addEventListener( FlexEvent.BUTTON_DOWN,myTabClickHandler );
}
}
private function myTabClickHandler(event:Event):void {
switch(event.currentTarget.label) {
// do whatever you need to do here
}
}

QTreeWidget set height of each row depending on content

I want to make editable cells with multi-lines content in QTreeWidget and I use for this purpose QPlainTextEdit as a delegate. I need to set proper size to all rows that switching between editing and displaying went smooth, without any visible changes.
rect = textEdit.blockBoundingRect(textEdit.firstVisibleBlock())
With this I can find out the height I need to set for the row, but I missing the place where I can do it.
How can I set proper height to QTreeWidget's rows on initialization stage and how to handle it's changes?
You need to reimplement delegate's sizeHint(). It will automatically handle row's height and width.
And note, that QTreeWidget::uniformRowHeight property must be false in this case, though it will slow tree element rendering if it contains many rows.

Making a Flex DataGrid scroll smoothly

I've noticed that the default behaviour for a DataGrid's vertical scroll bar is to scroll one row at a time. This is all well and good when the rows are all uniform and small (e.g. displaying a single line of text), but gets really ugly as soon as you have rows with variable heights.
I'm curious, is there a way to make DataGrid scrolling "smooth"? For instance, is there a way to have the DataGrid scroll by a set number of pixels, lines of text, etc. rather than scrolling one row at a time?
So far, the only solution I've managed to come up with is to place the DataGrid in a Canvas and have the Canvas do the scrolling instead of the DataGrid. The issue with this approach, though, is that as soon as the Canvas scrolls far enough, the DataGrid headers scroll off-screen. Ideally, I'd like to get the smooth-scrolling nature of the Canvas, but also keep the DataGrid headers visible. Is that possible?
The way that ItemRenderer's work in Flex 3 makes smooth scrolling difficult to achieve. Basically Flex recycles item renderers scrolled off of the top of the list as the display objects used for new data at the bottom of the list. Adobe's implementation of most list components in Flex 3 creates and adds these items as they come on to the screen rather than just off the screen, so they "pop in" and smooth scrolling isn't available. I'm not sure why they couldn't have done it in a similar manner for items +/- one position above or below the current scroll pane, but they didn't, and we're stuck with sticky scrolling by default.
Work-arounds do exist, though the one you've noted (dropping the datagrid into a canvas) negates the display-object saving intention of item renderers and incurs a performance cost. This will be fixed for most list-based Flex components in Flex 4, though it won't be fixed immediately for DataGrid. The DataGrid / AdvancedDataGrid component is maintained by a separate team based in India, last time I heard, and so it tends to be a bit behind the rest of the SDK.
I'd recommend trying something similar to this implementation of a smooth-scrolling list by Alex Harui. I'm not sure exactly how well it'd work for DataGrid or AdvancedDataGrid, but this is the most intuitive technique I can think of for making the list scroll correctly.
Try this... It's still based on Alex's code that was mentioned above. His should still be a great start for removing the snap-to-row behavior. Original source:
http://blogs.adobe.com/aharui/2008/03/smooth_scrolling_list.html
Alex's original some code for smooth vertical scrolling but that was not an issue I had with the DataGrid. It was smooth scrolling horizontally that I needed. I am using the DataGrid in an unorthodox manner for analyzing plain text reports output by our database (great way of providing visual feedback on a document). The code below allows content to go off screen and the user can scroll without that snap-to-column behavior.
You can adapt this to use the same math routines for vertical scrolling and then it will make scrolling possible and ignore the snap to row behavior. In particular switch the usage of the listContent.move method to move the contents vertically and use a inverse of the rounded pixel value you calculate from the vertical scroll bar (as opposed to my using the horizontal).
This method is bit simpler than Alex's method from the link above - a lot less code so try adapting and see how it works.
override protected function scrollHandler(event:Event):void
{
// Override the default scroll behavior to provide smooth horizontal scrolling and not the usual "snap-to-column" behavior
var scrEvt:ScrollEvent = event as ScrollEvent;
if(scrEvt.direction == ScrollEventDirection.HORIZONTAL) {
// Get individual components of a scroll bar for measuring and get a horizontal position to use
var scrDownArrow:DisplayObject = horizontalScrollBar.getChildAt(3);
var sctThumb:DisplayObject = horizontalScrollBar.getChildAt(2);
// I replaced maxHorizontalScrollPosition in Alex's code with "1300" to fix my exact application. In other situations you may finding using some property or different value is more appropriate. Don't rely on my choice.
var hPos:Number = Math.round((sctThumb.y - scrDownArrow.height) / (scrDownArrow.y - sctThumb.height - scrDownArrow.height) * 1300);
// Inverse the position to scroll the content to the left for large reports
listContent.move(hPos * -1, listContent.y);
}
// Go ahead and use the default handler for vertical scrolling
else {
super.scrollHandler(event);
}
}

Resources