Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Updated internals

  • Loading branch information...
commit fecc96990f7286b719a718f097b62a047314f81f 1 parent 13c5570
@soffes soffes authored
Showing with 42 additions and 21 deletions.
  1. +5 −1 Readme.markdown
  2. +2 −0  SSTableViewCell.h
  3. +35 −20 SSTableViewCell.m
View
6 Readme.markdown
@@ -1,5 +1,9 @@
## SSTableViewCell
-Simple, fast table view cell based on ABTableViewCell.
+Simple, fast table view cell based on [ABTableViewCell](http://blog.atebits.com/2008/12/fast-scrolling-in-tweetie-with-uitableview/).
Just override `drawContentView:` and write your `drawRect:` code for the cell's inner view.
+
+### Notes
+
+Unlike ABTableViewCell, it adds the custom view to UITableViewCell's `contentView` so it allows for resizing and `backgroundView` to `selectedBackgroundView` animations better.
View
2  SSTableViewCell.h
@@ -15,6 +15,8 @@
UIView *_cellView;
}
+@property (nonatomic, retain, readonly) UIView *cellView;
+
- (void)drawContentView:(CGRect)rect;
@end
View
55 SSTableViewCell.m
@@ -15,15 +15,25 @@ @implementation SSTableViewCellView
- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {
- self.backgroundColor = [UIColor whiteColor];
self.opaque = YES;
+ self.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
}
return self;
}
- (void)drawRect:(CGRect)rect {
- [(SSTableViewCell *)[self superview] drawContentView:rect];
+ SSTableViewCell *cell = (SSTableViewCell *)[[self superview] superview];
+ if (cell.highlighted == NO) {
+ [super drawRect:rect];
+ }
+ [cell drawContentView:rect];
+}
+
+
+- (void)setFrame:(CGRect)frame {
+ [super setFrame:frame];
+ [self setNeedsDisplay];
}
@end
@@ -31,22 +41,9 @@ - (void)drawRect:(CGRect)rect {
@implementation SSTableViewCell
-- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
- if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
- self.contentView.hidden = YES;
- self.backgroundView.hidden = YES;
- self.textLabel.hidden = YES;
- self.detailTextLabel.hidden = YES;
- self.imageView.hidden = YES;
-
- _cellView = [[SSTableViewCellView alloc] initWithFrame:CGRectZero];
- [self addSubview:_cellView];
- [self bringSubviewToFront:_cellView];
- [_cellView release];
- }
- return self;
-}
+@synthesize cellView = _cellView;
+#pragma mark UIView
- (void)setNeedsDisplay {
[super setNeedsDisplay];
@@ -57,13 +54,31 @@ - (void)setNeedsDisplay {
- (void)setFrame:(CGRect)frame {
[super setFrame:frame];
- CGRect bounds = [self bounds];
- bounds.size.height -= 1;
- _cellView.frame = bounds;
+ CGSize size = self.contentView.frame.size;
+ _cellView.frame = CGRectMake(0.0f, 0.0f, size.width, size.height);
[self setNeedsDisplay];
}
+#pragma mark UITableViewCell
+
+- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
+ if ((self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])) {
+ self.backgroundView.hidden = YES;
+ self.textLabel.hidden = YES;
+ self.detailTextLabel.hidden = YES;
+ self.imageView.hidden = YES;
+
+ _cellView = [[SSTableViewCellView alloc] initWithFrame:CGRectZero];
+ [self.contentView addSubview:_cellView];
+ [_cellView release];
+ }
+ return self;
+}
+
+
+#pragma mark Custom Drawing
+
- (void)drawContentView:(CGRect)rect {
// Subclasses should implement this
}
Please sign in to comment.
Something went wrong with that request. Please try again.