2017-01-10 8 views
3

私はいくつかのセクションを持つtableviewを持っています。私が欲しいのは、私がセクションのタイトル・ヘッダーを必要とするセクションから特定の表ビュー・セルを選択するときです。私はいくつかのSOの質問を見たが、何か有用なものを見つけられなかった。 ありがとうございます。選択したテーブルビューのセルからヘッダーセクションのタイトルを取得する方法は?

答えて

5

あなたはスウィフト

let sectionHeaderView = table.headerViewForSection(indexPath.section) 
let sectionTitle = sectionHeaderView?.textLabel?.text 

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

tableviewcellクリックメソッドで次のコードでタイトルを得ることができます

0

すると、「titleForHeaderInSection」テーブルのデリゲートを使用している場合は、タイトルを取得するには、次の試してみてください。

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 

     let title = self.tableView(tableView, titleForHeaderInSection: indexPath.row) 

    } 
関連する問題