Skip to content
This repository was archived by the owner on Mar 25, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions GCDExample/JKCallbacksTableViewCell.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
#import "JKCallbacksTableViewCell.h"


NSString * const kJKPrepareForReuseNotification = @"JKCallbacksTableViewCell_PrepareForReuse";

@implementation JKCallbacksTableViewCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
Expand Down Expand Up @@ -45,12 +43,4 @@ - (void)observeValueForKeyPath:(NSString *)keyPath
}
}

- (void)prepareForReuse
{
[[NSNotificationCenter defaultCenter] postNotificationName:kJKPrepareForReuseNotification
object:self];

[super prepareForReuse];
}

@end
36 changes: 10 additions & 26 deletions GCDExample/RootViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

@interface RootViewController()

- (void)tableViewCellIsPreparingForReuse:(NSNotification *)notification;
- (void)tableViewCellIsPreparingForReuse:(JKCallbacksTableViewCell *)cell;

@end

Expand Down Expand Up @@ -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];
}

Expand Down Expand Up @@ -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]];
Expand Down Expand Up @@ -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