Skip to content

Commit

Permalink
* New: TTTableView contentOrigin
Browse files Browse the repository at this point in the history
  • Loading branch information
joehewitt committed Aug 7, 2009
1 parent 94bab41 commit 0964fe9
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/TTTableView.m
Expand Up @@ -12,7 +12,7 @@

@implementation TTTableView

@synthesize highlightedLabel = _highlightedLabel;
@synthesize highlightedLabel = _highlightedLabel, contentOrigin = _contentOrigin;

///////////////////////////////////////////////////////////////////////////////////////////////////
// NSObject
Expand All @@ -21,6 +21,7 @@ - (id)initWithFrame:(CGRect)frame style:(UITableViewStyle)style {
if (self = [super initWithFrame:frame style:style]) {
_highlightedLabel = nil;
_highlightStartPoint = CGPointZero;
_contentOrigin = 0;
}
return self;
}
Expand Down Expand Up @@ -64,9 +65,37 @@ - (void)touchesEnded:(NSSet*)touches withEvent:(UIEvent*)event {
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UIScrollView

- (void)setContentSize:(CGSize)size {
if (_contentOrigin) {
CGFloat minHeight = self.height + _contentOrigin;
if (size.height < minHeight) {
size.height = self.height + _contentOrigin;
}
}

CGFloat y = self.contentOffset.y;
[super setContentSize:size];

if (_contentOrigin) {
self.contentOffset = CGPointMake(0, y);
}
}

///////////////////////////////////////////////////////////////////////////////////////////////////
// UITableView

- (void)reloadData {
CGFloat y = self.contentOffset.y;
[super reloadData];

if (_contentOrigin) {
self.contentOffset = CGPointMake(0, y);
}
}

- (void)selectRowAtIndexPath:(NSIndexPath *)indexPath animated:(BOOL)animated
scrollPosition:(UITableViewScrollPosition)scrollPosition {
if (!_highlightedLabel) {
Expand Down
2 changes: 2 additions & 0 deletions src/Three20/TTTableView.h
Expand Up @@ -13,8 +13,10 @@
@interface TTTableView : UITableView {
TTStyledTextLabel* _highlightedLabel;
CGPoint _highlightStartPoint;
CGFloat _contentOrigin;
}

@property(nonatomic,retain) TTStyledTextLabel* highlightedLabel;
@property(nonatomic) CGFloat contentOrigin;

@end

0 comments on commit 0964fe9

Please sign in to comment.