1.自定义UITableViewHeaderFooterView
头文件:
#pragma mark - ClickedHeader
@interface ClickedHeader : UITableViewHeaderFooterView
@property (assign)BOOL clicked;
@property (assign)uint32_t section;
@property (nonatomic, strong) UIButton* button;
- (id)initWithClickedHeaderReuseIdentifier:(id)sender;
@end
实现文件:
#pragma mark - ClickedHeader
@implementation ClickedHeader
- (id)initWithClickedHeaderReuseIdentifier:(id)sender
{
self = [super initWithReuseIdentifier:ClickedHeaderReuseIdentifier];
if (self)
{
_clicked = false;
self.button = [UIButton buttonWithType:UIButtonTypeCustom];
[self.button setFrame:CGRectMake(0, 0, WIDTH, CLICK_BUTTON_HEIGHT)];
[self.button setBackgroundColor:[UIColor lightGrayColor]];
[self.button addTarget:self
action:@selector(buttonClicked:)
forControlEvents:UIControlEventTouchUpInside];
[self.contentView addSubview:self.button];
}
return self;
}
- (void)buttonClicked:(id)sender
{
_clicked = !_clicked;
ClickedMarked* obj = [[ClickedMarked alloc] initWithSection:self.section
andClicked:self.clicked];
NSNotificationCenter* noti = NULL;
noti = [NSNotificationCenter defaultCenter];
[noti postNotificationName:kReloadTableNotification object:obj];
}
@end
这里注意的是,重用的是一个固定标志符,所以直接self = [super initWithReuseIdentifier: XXXXXXXX]; 即可,并不用传参。