Skip to content

Commit

Permalink
Merge pull request twitter-archive#63 from bww/master
Browse files Browse the repository at this point in the history
Table view header fixes
  • Loading branch information
Loren Brichter committed Sep 7, 2011
2 parents da9c067 + 496fe68 commit 3284fa2
Showing 1 changed file with 31 additions and 10 deletions.
41 changes: 31 additions & 10 deletions lib/UIKit/TUITableView.m
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ - (id)initWithNumberOfRows:(NSUInteger)n sectionIndex:(NSInteger)s tableView:(TU
- (void)dealloc
{
if(rowInfo) free(rowInfo);
NSLog(@"RELEASE HEADER: %@ (%@)", _headerView, _headerView.superview);
[_headerView release];
[super dealloc];
}
Expand Down Expand Up @@ -144,6 +145,7 @@ - (TUIView *)headerView
@end

@interface TUITableView (Private)
- (void)_updateSectionInfo;
- (void)_updateDerepeaterViews;
@end

Expand Down Expand Up @@ -265,19 +267,39 @@ - (CGRect)rectForRowAtIndexPath:(TUIFastIndexPath *)indexPath
return CGRectZero;
}

- (NSArray *)_freshSectionInfo
{
/**
* @brief Update section info
*
* The previous section info is released and new section info is created.
*/
- (void)_updateSectionInfo {

if(_sectionInfo != nil){

// remove any visible headers, they should be re-added when the table is laid out
for(TUITableViewSection *section in _sectionInfo){
TUIView *headerView;
if((headerView = [section headerView]) != nil){
[headerView removeFromSuperview];
}
}

// clear visible section headers
[_visibleSectionHeaders removeAllIndexes];
// clear the section info array
[_sectionInfo release];

}

NSInteger numberOfSections = 1;

if(_tableFlags.dataSourceNumberOfSectionsInTableView){
numberOfSections = [_dataSource numberOfSectionsInTableView:self];
}

NSMutableArray *sections = [NSMutableArray arrayWithCapacity:numberOfSections];
NSMutableArray *sections = [[NSMutableArray alloc] initWithCapacity:numberOfSections];

int s;
CGFloat offset = [_headerView bounds].size.height - self.contentInset.top;
for(s = 0; s < numberOfSections; ++s) {
for(int s = 0; s < numberOfSections; ++s) {
TUITableViewSection *section = [[TUITableViewSection alloc] initWithNumberOfRows:[_dataSource tableView:self numberOfRowsInSection:s] sectionIndex:s tableView:self];
[section _setupRowHeights];
section.sectionOffset = offset;
Expand All @@ -287,8 +309,8 @@ - (NSArray *)_freshSectionInfo
}

_contentHeight = offset - self.contentInset.bottom;
_sectionInfo = sections;

return sections;
}

- (void)_enqueueReusableCell:(TUITableViewCell *)cell
Expand Down Expand Up @@ -657,6 +679,7 @@ - (BOOL)_preLayoutCells
CGRect bounds = self.bounds;

if(!_sectionInfo || !CGSizeEqualToSize(bounds.size, _lastSize)) {

// save scroll position
CGFloat previousOffset = 0.0f;
TUIFastIndexPath *savedIndexPath = nil;
Expand All @@ -682,9 +705,7 @@ - (BOOL)_preLayoutCells
}
}


[_sectionInfo release];
_sectionInfo = [[self _freshSectionInfo] retain]; // calculates new contentHeight here
[self _updateSectionInfo]; // clean up any previous section info and recreate it
self.contentSize = CGSizeMake(self.bounds.size.width, _contentHeight);

_lastSize = bounds.size;
Expand Down

0 comments on commit 3284fa2

Please sign in to comment.