#import <UIKit/UIKit.h> @interface YGSectionHeaderView : UIView @property NSUInteger section; @property (nonatomic, weak) UITableView *tableView; @end
#import "YGSectionHeaderView.h"
@implementation YGSectionHeaderView
- (void)setFrame:(CGRect)frame{
CGRect sectionRect = [self.tableView rectForSection:self.section];
CGRect newFrame = CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(sectionRect), CGRectGetWidth(frame), CGRectGetHeight(frame));
[super setFrame:newFrame];
}
@end- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
YGSectionHeaderView *sectionHead = [[YGSectionHeaderView alloc] init];
sectionHead.section = section;
sectionHead.tableView = tableView;
return sectionHead;
}使 UITableViewStylePlain Style 的TableView header 不浮动,像Group Style 那样固定,跟随Tableview 滚动,而不会停在顶端。
原文:http://blog.csdn.net/dacaiguoguo/article/details/36929103