From 1b1f0448fe73138a8a50983313a6dc72cfd7ec86 Mon Sep 17 00:00:00 2001 From: lockedscope Date: Wed, 12 Sep 2012 23:02:11 +0300 Subject: [PATCH 1/3] Update GCDExample/RootViewController.m Resetting reusable cell directly. --- GCDExample/RootViewController.m | 33 ++++++++++++--------------------- 1 file changed, 12 insertions(+), 21 deletions(-) diff --git a/GCDExample/RootViewController.m b/GCDExample/RootViewController.m index 8764420..143d0bc 100644 --- a/GCDExample/RootViewController.m +++ b/GCDExample/RootViewController.m @@ -20,7 +20,7 @@ @interface RootViewController() -- (void)tableViewCellIsPreparingForReuse:(NSNotification *)notification; +- (void)tableViewCellIsPreparingForReuse:(JKCallbacksTableViewCell *)cell; @end @@ -69,20 +69,11 @@ - (void)viewDidLoad imageArray = [[[NSFileManager defaultManager] contentsOfDirectoryAtPath:imageFolder error:NULL] retain]; - // Register for our table view cell notification - [[NSNotificationCenter defaultCenter] addObserver:self - selector:@selector(tableViewCellIsPreparingForReuse:) - name:kJKPrepareForReuseNotification - object:nil]; [super viewDidLoad]; } - (void)viewDidUnload { - [[NSNotificationCenter defaultCenter] removeObserver:self - name:kJKPrepareForReuseNotification - object:nil]; - [super viewDidUnload]; } @@ -115,6 +106,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cell = [[[JKCallbacksTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } + else + { + [self tableViewCellIsPreparingForReuse:cell]; + } // Get the filename to load. NSString *imageFilename = [imageArray objectAtIndex:[indexPath row]]; @@ -166,18 +161,14 @@ - (UITableViewCell *)tableView:(UITableView *)tableView #pragma mark - -- (void)tableViewCellIsPreparingForReuse:(NSNotification *)notification +- (void)tableViewCellIsPreparingForReuse:(JKCallbacksTableViewCell *)cell { - if ([[notification object] isKindOfClass:[JKCallbacksTableViewCell class]]) { - JKCallbacksTableViewCell *cell = (JKCallbacksTableViewCell *)[notification object]; - - objc_setAssociatedObject(cell, - kIndexPathAssociationKey, - nil, - OBJC_ASSOCIATION_RETAIN); - - [[cell imageView] setImage:nil]; - } + objc_setAssociatedObject(cell, + kIndexPathAssociationKey, + nil, + OBJC_ASSOCIATION_RETAIN); + + [[cell imageView] setImage:nil]; } @end From 83e18fc8ef4990ff9bf80541886377f2ba8bd537 Mon Sep 17 00:00:00 2001 From: lockedscope Date: Wed, 12 Sep 2012 23:12:24 +0300 Subject: [PATCH 2/3] Update GCDExample/JKCallbacksTableViewCell.m MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cell resetting logic removed from prepareForReuse to UITableView's cellForRowAtIndexPath. "If a UITableViewCell object is reusable—that is, it has a reuse identifier—this method is invoked just before the object is returned from the UITableView method dequeueReusableCellWithIdentifier:." --- GCDExample/JKCallbacksTableViewCell.m | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/GCDExample/JKCallbacksTableViewCell.m b/GCDExample/JKCallbacksTableViewCell.m index 2e9d526..7a0628b 100644 --- a/GCDExample/JKCallbacksTableViewCell.m +++ b/GCDExample/JKCallbacksTableViewCell.m @@ -9,8 +9,6 @@ #import "JKCallbacksTableViewCell.h" -NSString * const kJKPrepareForReuseNotification = @"JKCallbacksTableViewCell_PrepareForReuse"; - @implementation JKCallbacksTableViewCell - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier @@ -45,12 +43,4 @@ - (void)observeValueForKeyPath:(NSString *)keyPath } } -- (void)prepareForReuse -{ - [[NSNotificationCenter defaultCenter] postNotificationName:kJKPrepareForReuseNotification - object:self]; - - [super prepareForReuse]; -} - @end From 2520ca7a5c5c6b4721f5c857126b6fd7baf61ecd Mon Sep 17 00:00:00 2001 From: lockedscope Date: Wed, 12 Sep 2012 23:23:53 +0300 Subject: [PATCH 3/3] Update GCDExample/RootViewController.m So, method call removed also. --- GCDExample/RootViewController.m | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/GCDExample/RootViewController.m b/GCDExample/RootViewController.m index 143d0bc..3abf233 100644 --- a/GCDExample/RootViewController.m +++ b/GCDExample/RootViewController.m @@ -108,7 +108,12 @@ - (UITableViewCell *)tableView:(UITableView *)tableView } else { - [self tableViewCellIsPreparingForReuse:cell]; + objc_setAssociatedObject(cell, + kIndexPathAssociationKey, + nil, + OBJC_ASSOCIATION_RETAIN); + + [[cell imageView] setImage:nil]; } // Get the filename to load. @@ -159,16 +164,4 @@ - (UITableViewCell *)tableView:(UITableView *)tableView return cell; } -#pragma mark - - -- (void)tableViewCellIsPreparingForReuse:(JKCallbacksTableViewCell *)cell -{ - objc_setAssociatedObject(cell, - kIndexPathAssociationKey, - nil, - OBJC_ASSOCIATION_RETAIN); - - [[cell imageView] setImage:nil]; -} - @end