Add a button section Header?

ios, iphone, objective-c, uitableview

Solution

Try like this May be it helps you,

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    //Headerview
    UIView *myView = [[[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 20.0)] autorelease];
     UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd];
    [button setFrame:CGRectMake(275.0, 5.0, 30.0, 30.0)];
    button.tag = section;
    button.hidden = NO;
    [button setBackgroundColor:[UIColor clearColor]];
    [button addTarget:self action:@selector(insertParameter:) forControlEvents:UIControlEventTouchDown];
    [myView addSubview:button];
      return myView;
}

you can change the height of the header section here

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 40.0;
}

for getting same Button image you can take your custom image ,by using default image you can't show like that.

Problem

I have a tableView with two section I want to add a button in section header(Action Button) It is possible to do same in the sample image? ``` - (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { if(section ==0) { return 0; } else{ UIView *myView = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 300.0, 20.0)]; UIButton *button = [UIButton buttonWithType:UIButtonTypeContactAdd]; [button setFrame:CGRectMake(275.0, 5.0, 30.0, 30.0)]; button.tag = section; button.hidden = NO; [button setBackgroundColor:[UIColor clearColor]]; [button addTarget:self action:@selector(insertParameter:) forControlEvents:UIControlEventTouchDown]; [myView addSubview:button]; return myView; } } ```

Original source