Animating row height changes for view-based table view
Animating row height changes for view-based table view
- Subject: Animating row height changes for view-based table view
- From: Martin Hewitson <email@hidden>
- Date: Sun, 07 Apr 2013 10:26:52 +0200
Dear list,
I'm trying to put together a UI which has a view-based table view. Each item in the table view has advanced settings which can be accessed by toggling an 'advanced' button on the item's view. The row then expands to reveal the advanced items. I have a couple of problems:
1) The advanced components (extra buttons etc) move when the row's view resizes. I rather just want them to be hidden out of view.
2) When expanding a row's view, I would like to scroll the table so that the full view is visible. I was trying to figure out a way to use -scrollRectToVisible: but I would need to do that after the animation finishes, I guess.
I have a test program setup to figure this all out (I'm new to view-based table views!) where I have a button on each row's view which triggers a notification which I handle in my table controller like this:
- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row
{
CGFloat height = 24.0;
AThing *item = [[self items] objectAtIndex:row];
if (item.showAdvanced) {
height = 100.0;
}
return height;
}
- (void) handleAdvancedToggle:(NSNotification*)aNote
{
MHItemCellView *view = [aNote object];
NSInteger row = [self.tableView rowForView:view];
[NSAnimationContext beginGrouping];
[[NSAnimationContext currentContext] setDuration:0.25];
[self.tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndex:row]];
NSRect r = [self.tableView rectOfRow:row];
[self.tableView scrollRectToVisible:r];
[NSAnimationContext endGrouping];
}
So, in short, the expanding of the rows works nicely, except for the NSViews which should be hidden/revealed move in the view, despite having deselected the necessary struts in IB (haven't tried auto-layout here yet). And, I need a better way to scroll the full row to be visible.
Can anyone suggest how to improve on this? Is this even the right approach for what I'm trying to achieve?
Many thanks,
Martin
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden