試一試它的工作對我來說就像魅力,
我在willDisplayHeaderView委託方法添加的UIButton,
1)添加按鈕
- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section
{
UITableViewHeaderFooterView *header = (UITableViewHeaderFooterView *)view;
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[header addSubview:button];
[button setFrame:CGRectMake(200, -10, 300, 44)];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button.titleLabel setFont:[UIFont fontWithName:@"Helvetica" size:35]];
[button setTitle:@"Add" forState:UIControlStateNormal];
[button addTarget:self action:@selector(addbuttonclicked) forControlEvents:UIControlEventTouchUpInside]; }
2)添加按鈕動作
-(void)addbuttonclicked
{
//Add code
}
希望這對某些人有幫助。