Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the header section title from selected tableview cell?

I am having a tableview which has several section. What I want is when I select a particular tableview cell from section I want title header of that section. I looked several SO question but didn't find out anything useful. Thanks in advance.

like image 629
shahin ali agharia Avatar asked Jan 10 '17 05:01

shahin ali agharia


1 Answers

You can get title with following code on tableviewcell click method

UITableViewHeaderFooterView* header =[self.tableView headerViewForSection:indexPath.section];
NSLog(@"Header text = %@", header.textLabel.text);

In Swift

let sectionHeaderView = table.headerViewForSection(indexPath.section)
let sectionTitle = sectionHeaderView?.textLabel?.text
like image 183
Matloob Hasnain Avatar answered Nov 08 '22 20:11

Matloob Hasnain