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 diff --git a/GCDExample/RootViewController.m b/GCDExample/RootViewController.m index 8764420..3abf233 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,15 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cell = [[[JKCallbacksTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; } + else + { + objc_setAssociatedObject(cell, + kIndexPathAssociationKey, + nil, + OBJC_ASSOCIATION_RETAIN); + + [[cell imageView] setImage:nil]; + } // Get the filename to load. NSString *imageFilename = [imageArray objectAtIndex:[indexPath row]]; @@ -164,20 +164,4 @@ - (UITableViewCell *)tableView:(UITableView *)tableView return cell; } -#pragma mark - - -- (void)tableViewCellIsPreparingForReuse:(NSNotification *)notification -{ - if ([[notification object] isKindOfClass:[JKCallbacksTableViewCell class]]) { - JKCallbacksTableViewCell *cell = (JKCallbacksTableViewCell *)[notification object]; - - objc_setAssociatedObject(cell, - kIndexPathAssociationKey, - nil, - OBJC_ASSOCIATION_RETAIN); - - [[cell imageView] setImage:nil]; - } -} - @end