Skip to content

Commit

Permalink
added TUITableViewStyleGrouped
Browse files Browse the repository at this point in the history
section headers now only stick when using TUITableViewStyleGrouped
  • Loading branch information
joshaber committed Apr 10, 2012
1 parent c9adc20 commit 9b10d1a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 21 deletions.
1 change: 1 addition & 0 deletions lib/UIKit/TUITableView.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

typedef enum {
TUITableViewStylePlain, // regular table view
TUITableViewStyleGrouped, // grouped table view—headers stick to the top of the table view and scroll with it
} TUITableViewStyle;

typedef enum {
Expand Down
44 changes: 23 additions & 21 deletions lib/UIKit/TUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -732,27 +732,29 @@ - (void)_layoutSectionHeaders:(BOOL)visibleHeadersNeedRelayout
if(section.headerView != nil) {
CGRect headerFrame = [self rectForHeaderOfSection:index];

// check if this header needs to be pinned
if(CGRectGetMaxY(headerFrame) > CGRectGetMaxY(visible)) {
headerFrame.origin.y = CGRectGetMaxY(visible) - headerFrame.size.height;
pinnedHeader = section.headerView;
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = TRUE;
}
}else if((pinnedHeader != nil) && (CGRectGetMaxY(headerFrame) > pinnedHeader.frame.origin.y)) {
// this header is intersecting with the pinned header, so we push the pinned header upwards.
CGRect pinnedHeaderFrame = pinnedHeader.frame;
pinnedHeaderFrame.origin.y = CGRectGetMaxY(headerFrame);
pinnedHeader.frame = pinnedHeaderFrame;
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = FALSE;
}
}else{
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = FALSE;
if(_style == TUITableViewStyleGrouped) {
// check if this header needs to be pinned
if(CGRectGetMaxY(headerFrame) > CGRectGetMaxY(visible)) {
headerFrame.origin.y = CGRectGetMaxY(visible) - headerFrame.size.height;
pinnedHeader = section.headerView;
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = TRUE;
}
}else if((pinnedHeader != nil) && (CGRectGetMaxY(headerFrame) > pinnedHeader.frame.origin.y)) {
// this header is intersecting with the pinned header, so we push the pinned header upwards.
CGRect pinnedHeaderFrame = pinnedHeader.frame;
pinnedHeaderFrame.origin.y = CGRectGetMaxY(headerFrame);
pinnedHeader.frame = pinnedHeaderFrame;
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = FALSE;
}
}else{
// if the header is a TUITableViewSectionHeader notify it of it's pinned state
if([section.headerView isKindOfClass:[TUITableViewSectionHeader class]]){
((TUITableViewSectionHeader *)section.headerView).pinnedToViewport = FALSE;
}
}
}

Expand Down

0 comments on commit 9b10d1a

Please sign in to comment.