From 734653ee4a41c7d44dd15f0401b34d598353a992 Mon Sep 17 00:00:00 2001 From: Fabio Pelosin Date: Mon, 30 Jul 2012 22:40:29 +0200 Subject: [PATCH] [PrettyTableViewCell] Correctly initialize from a storyboard. UIStoryboard calls `initWithCoder:`. --- PrettyKit/Cells/PrettyTableViewCell.m | 44 +++++++++++++++++---------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/PrettyKit/Cells/PrettyTableViewCell.m b/PrettyKit/Cells/PrettyTableViewCell.m index 003f607..713d4d3 100644 --- a/PrettyKit/Cells/PrettyTableViewCell.m +++ b/PrettyKit/Cells/PrettyTableViewCell.m @@ -376,27 +376,39 @@ - (void)initializeVars self.shadowOpacity = default_shadow_opacity; } +- (void)commonInit { + [self.contentView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:nil]; + + + PrettyTableViewCellBackground *bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame + behavior:CellBackgroundBehaviorNormal]; + bg.cell = self; + self.backgroundView = bg; + [bg release]; + + bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame + behavior:CellBackgroundBehaviorSelected]; + bg.cell = self; + self.selectedBackgroundView = bg; + [bg release]; + + [self initializeVars]; +} + - (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier { self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]; if (self) { + [self commonInit]; + } + return self; +} - [self.contentView addObserver:self forKeyPath:@"frame" options:NSKeyValueObservingOptionOld context:nil]; - - - PrettyTableViewCellBackground *bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame - behavior:CellBackgroundBehaviorNormal]; - bg.cell = self; - self.backgroundView = bg; - [bg release]; - - bg = [[PrettyTableViewCellBackground alloc] initWithFrame:self.frame - behavior:CellBackgroundBehaviorSelected]; - bg.cell = self; - self.selectedBackgroundView = bg; - [bg release]; - - [self initializeVars]; +- (id)initWithCoder:(NSCoder *)aDecoder +{ + self = [super initWithCoder:aDecoder]; + if (self) { + [self commonInit]; } return self; }