Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Updated internals

  • Loading branch information...
commit fecc96990f7286b719a718f097b62a047314f81f 1 parent 13c5570
Sam Soffes soffes authored

Showing 3 changed files with 42 additions and 21 deletions. Show diff stats Hide diff stats

  1. +5 1 Readme.markdown
  2. +2 0  SSTableViewCell.h
  3. +35 20 SSTableViewCell.m
6 Readme.markdown
Source Rendered
... ... @@ -1,5 +1,9 @@
1 1 ## SSTableViewCell
2 2
3   -Simple, fast table view cell based on ABTableViewCell.
  3 +Simple, fast table view cell based on [ABTableViewCell](http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/).
4 4
5 5 Just override `drawContentView:` and write your `drawRect:` code for the cell's inner view.
  6 +
  7 +### Notes
  8 +
  9 +Unlike ABTableViewCell, it adds the custom view to UITableViewCell's `contentView` so it allows for resizing and `backgroundView` to `selectedBackgroundView` animations better.
2  SSTableViewCell.h
@@ -15,6 +15,8 @@
15 15 UIView *_cellView;
16 16 }
17 17
  18 +@property (nonatomic, retain, readonly) UIView *cellView;
  19 +
18 20 - (void)drawContentView:(CGRect)rect;
19 21
20 22 @end
55 SSTableViewCell.m
@@ -15,15 +15,25 @@ @implementation SSTableViewCellView
15 15
16 16 - (id)initWithFrame:(CGRect)frame {
17 17 if ((self = [super initWithFrame:frame])) {
18   - self.backgroundColor = [UIColor whiteColor];
19 18 self.opaque = YES;
  19 + self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
20 20 }
21 21 return self;
22 22 }
23 23
24 24
25 25 - (void)drawRect:(CGRect)rect {
26   - [(SSTableViewCell *)[self superview] drawContentView:rect];
  26 + SSTableViewCell *cell = (SSTableViewCell *)[[self superview] superview];
  27 + if (cell.highlighted == NO) {
  28 + [super drawRect:rect];
  29 + }
  30 + [cell drawContentView:rect];
  31 +}
  32 +
  33 +
  34 +- (void)setFrame:(CGRect)frame {
  35 + [super setFrame:frame];
  36 + [self setNeedsDisplay];
27 37 }
28 38
29 39 @end
@@ -31,22 +41,9 @@ - (void)drawRect:(CGRect)rect {
31 41
32 42 @implementation SSTableViewCell
33 43
34   -- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
35   - if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
36   - self.contentView.hidden = YES;
37   - self.backgroundView.hidden = YES;
38   - self.textLabel.hidden = YES;
39   - self.detailTextLabel.hidden = YES;
40   - self.imageView.hidden = YES;
41   -
42   - _cellView = [[SSTableViewCellView alloc] initWithFrame:CGRectZero];
43   - [self addSubview:_cellView];
44   - [self bringSubviewToFront:_cellView];
45   - [_cellView release];
46   - }
47   - return self;
48   -}
  44 +@synthesize cellView = _cellView;
49 45
  46 +#pragma mark UIView
50 47
51 48 - (void)setNeedsDisplay {
52 49 [super setNeedsDisplay];
@@ -57,13 +54,31 @@ - (void)setNeedsDisplay {
57 54 - (void)setFrame:(CGRect)frame {
58 55 [super setFrame:frame];
59 56
60   - CGRect bounds = [self bounds];
61   - bounds.size.height -= 1;
62   - _cellView.frame = bounds;
  57 + CGSize size = self.contentView.frame.size;
  58 + _cellView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
63 59 [self setNeedsDisplay];
64 60 }
65 61
66 62
  63 +#pragma mark UITableViewCell
  64 +
  65 +- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
  66 + if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
  67 + self.backgroundView.hidden = YES;
  68 + self.textLabel.hidden = YES;
  69 + self.detailTextLabel.hidden = YES;
  70 + self.imageView.hidden = YES;
  71 +
  72 + _cellView = [[SSTableViewCellView alloc] initWithFrame:CGRectZero];
  73 + [self.contentView addSubview:_cellView];
  74 + [_cellView release];
  75 + }
  76 + return self;
  77 +}
  78 +
  79 +
  80 +#pragma mark Custom Drawing
  81 +
67 82 - (void)drawContentView:(CGRect)rect {
68 83 // Subclasses should implement this
69 84 }

0 comments on commit fecc969

Please sign in to comment.
Something went wrong with that request. Please try again.