• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Animating a UITableViewCell changing size
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Animating a UITableViewCell changing size


  • Subject: Animating a UITableViewCell changing size
  • From: Thomas Davie <email@hidden>
  • Date: Thu, 13 Oct 2011 10:35:37 +0100

Dear list,

I'm trying to construct a UITableViewCell with what is essentially a disclosure triangle on it.  When that's tapped, the cell expands to show additional information.  I currently hack this with code along these lines:

    NSArray *cellPaths = [tableView indexPathsForVisibleRows];
    [UIView animateWithDuration:0.3
                     animations:^ ()
     {
         MyCustomCell *cell = [tableView cellForRowAtIndexPath:indexPath];
         NSUInteger minRow = [indexPath row];
         BOOL d = ![cell disclosed];
         [cell setDisclosed:d];
         [disclosures setObject:[NSNumber numberWithBool:d] forKey:[cell statName]];
         for (NSIndexPath *p in cellPaths)
         {
             if ([p row] > minRow)
             {
                 MyCustomCell *c = [tableView cellForRowAtIndexPath:p]
                 [c setFrame:CGRectMake([c frame].origin.x, d ? [c frame].origin.y + kDisclosureOffset : [c frame].origin.y - kDisclosureOffset, [c frame].size.width, [c frame].size.height)];
             }
         }

     }
                     completion:^ (BOOL finished)
     {
         [tableView reloadRowsAtIndexPaths:cellPaths withRowAnimation:UITableViewRowAnimationNone];
     }];

This for the most part works well except for one case – collapsing the cells.  When this happens, the table view does not have cells for the rows that are not yet visible, but become visible as the cell collapses.  Because of this, a blank area comes into view at the bottom of the table view, and then flashes as it gets replaced by the newly generated rows.

I've tried using cellForRowAtIndexPath: to grab the cells off the bottom, but these come back as nil, as the table view doesn't think it needs to show them.  The only other thing I can conjor in my mind is to call something similar to the data source method directly to construct cells myself, add them to the TV, animate them in, remove them and reload the table view.  However, this does not solve one final issue – what happens when the table view is scrolled near to the bottom and there are no cells to add.

If anyone could recommend a good way forward here, I'd be appreciative.

Thanks

Tom Davie


_______________________________________________

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

  • Follow-Ups:
    • Re: Animating a UITableViewCell changing size
      • From: Luke Hiesterman <email@hidden>
  • Prev by Date: Simple PDF generation code not working as intended
  • Next by Date: PrintOperation reappears when cancelled
  • Previous by thread: Re: Simple PDF generation code not working as intended
  • Next by thread: Re: Animating a UITableViewCell changing size
  • Index(es):
    • Date
    • Thread