2016-04-19 5 views
3

カスタムビューを作成し、tableViewセクションのヘッダーに追加しました。カスタムTableviewセクションヘッダーからindexPathを取得

func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { 

     if section == 2 { 

      if (headerView == nil) { 
       headerView = CustomHeaderSection(frame: CGRectMake(0,0,self.view.bounds.width,38)) 
      } 
      headerView!.delegate = self 

      if isExpandableCell { 

       headerView!.arrowImage.transform = CGAffineTransformIdentity 

      }else { 

       headerView!.arrowImage.transform = CGAffineTransformMakeRotation(CGFloat(M_PI)) 

      } 
      return headerView 

     } 

     return nil 
    } 

私は、カスタムビューのボタンをテーブルビューセクションに追加しました。今、indexPathをクリックすると、どのように取得されますか?

+0

のみインデックスパスがあります。しかし、ヘッダーが属するセクション番号を取得する現実的な方法はおそらくあります。 – NSGangster

答えて

-1

セクションヘッダービューのtagプロパティをtableView(tableView: UITableView, viewForHeaderInSection section: Int)メソッドのセクション数に割り当てることができます。あなたの関数で

+0

しかし、私はheaderViewを一度しか初期化していません。だから私はタグを割り当てる場合、私はそれをチェックすることができないように変更されます。 –

+0

テーブルビューにヘッダーが1つしかありませんか? –

0

あなたはindexPath

override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell { 
let cell = tableView.dequeueReusableCellWithIdentifier("FoldingCell", forIndexPath: indexPath) as! myTableViewCell 
... 
cell.myButton.tag = indexPath.row 
... 
} 
1

CustomHeaderクラスのセクション番号の変数を宣言しviewForHeaderInSection内でインスタンス化しながら、その値を割り当てる()と同じになるようにボタンにタグIDを追加することができます。

ターゲットボタンアクションを同じクラス内に実装します。だから、tapをself.sectionを取得し、ViewControllerに渡します。

void onButtonTap (id sender) 
     { 
      UIButton button = (UIButton)sender; 

     this.sectionHeaderViewDelegate.buttonTapped (this.section); 

     } 
関連する問題