Arun
Arun

Reputation: 733

UITableView section clicked in Viewforheaderinsection

I have a created custom UIButton in UITableView viewForHeaderInSection. Now when i click on the button within the section how will i know which section is clicked? Please help.

Upvotes: 2

Views: 413

Answers (4)

Maulik Vekariya
Maulik Vekariya

Reputation: 554

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIbutton *btn =[[UIButton alloc]init];
btn.tag=section;// this tag property will differentiate button for different section
}

by this you can access btn and add event on that burron

Upvotes: 1

h.kishan
h.kishan

Reputation: 681

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIbutton *button =[[UIButton alloc]init];
    button.tag=section;// this tag property will differentiate button for different section
}

Upvotes: 0

Paras Joshi
Paras Joshi

Reputation: 20551

when you add button in viewForHeaderInSection , just set tag with section number like bellow.,..

button.tag = section;

and when your button clicked at that time you can get that number with bellow code...

- (IBAction)yourButton_Clicked:(id) sender  
{
    NSLog(@"Section Number => %d",[sender tag]);
}

Upvotes: 3

NHS
NHS

Reputation: 409

In didselectrowatindexpath check for if(index path.section) is equal to the section you want the action.

Upvotes: -1

Related Questions