Home:ALL Converter>Is there any method like tableViewWillEndDisplayingCell in iOS for UITableViewDelegate?

Is there any method like tableViewWillEndDisplayingCell in iOS for UITableViewDelegate?

Ask Time:2015-08-26T22:44:03         Author:KaroCodes

Json Formatter

I would like to fade cell in table view in my iPhone application before it disappears. When it is about to appear I use

- (void) tableView: (UITableView *) tableView
   willDisplayCell: (UITableViewCell *) cell
 forRowAtIndexPath: (NSIndexPath *) indexPath

to change alpha from zero to 1 with 0.3 sec animation.

I would like to to the same but from 1 to zero when it is about to disappear. Is it any method similar to the one above or how else can I do that?

I don't want to use standard iOS UITableViewRowAnimationFade because I don't want any other transitions while reloading table.

EDIT: I am reloading content of the table view. Let say that I have a button which I click and it reloads data in my table. That is when I want to fade out existing cells and fade in new ones.

The controller I am using is a basic UIViewController implementing UITableViewDataSource UITableViewDelegate UIScrollViewDelegate protocols.

Author:KaroCodes,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/32229739/is-there-any-method-like-tableviewwillenddisplayingcell-in-ios-for-uitableviewde
KaroCodes :

I found a solution.\n\nJust before calling [self.tableView reloadData] I am animating all visible cells to fade out. I get all visible cells and iterate over them by \n\nfor (NSIndexPath *indexPath in [self.tableView indexPathsForVisibleRows])\n{\n // here I animate cells to fade out\n}\n\n\n(thanks @AlexKoren for showing me the way to iterate over visible cells).\n\nBecause I was using [self.tableView reloadData] without any additional iOS built-in animation the cells were just disappearing. So now they are fading first and then my new cells are fading in with animation defined in\n\n- (void) tableView: (UITableView *) tableView\n willDisplayCell: (UITableViewCell *) cell\n forRowAtIndexPath: (NSIndexPath *) indexPath\n\n\nImportant: I am reloading table view after animation is finished. If I called [self.tableView reloadData] just after iterating over cells it would reload table before animation was displayed. Because I know how long it takes to finish animation I use\n\ndispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delay * NSEC_PER_SEC);\ndispatch_after(popTime, dispatch_get_main_queue(), ^(void)\n {\n [self.tableView reloadData];\n });\n\n\nwith delay calculated before.",
2015-08-27T12:59:54
AlexKoren :

This is a bit of a hack, but should work:\n\n- (void)scrollViewDidScroll:(UIScrollView *)scrollView {\n //loop through visible indexPaths\n for (NSIndexPath *indexPath in [self.tableView indexPathsForVisibleRows]) {\n //get each cell\n UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];\n //get its location\n CGRect rectInTableView = [self.tableView rectForRowAtIndexPath:indexPath];\n //set its alpha based on whether or not its going off the screen at the top.\n cell.alpha = 1 + rectInTableView.origin.y / rectInTableView.size.height;\n }\n\n}\n",
2015-08-26T15:02:43
yy