2017-07-28 33 views
0

我需要獲取在所選行的Headerview中設置的字符串。我需要這些信息來決定該行將被髮送到哪個視圖。我已經有了Row名字。但是我需要在Headerview中使用的字符串的名稱。Swift:如何從headerViewer獲取UItextlabel

+0

您想在行上點擊時獲取節標題文本嗎?對 ? – Ujesh

+0

請把代碼質疑你的嘗試。 – Ujesh

回答

1

按照步驟

  1. 的部分的標題名稱等採取陣列和聲明以上viewDidLoad中方法

    let sectionHeaderArray = ["Header1", "Header2"] 
    
  2. 實現用於視圖的方法的節頭

    func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) 
    { 
        let header = view as! UITableViewHeaderFooterView 
        header.textLabel?.text = self.sectionHeaderArray[section] 
    } 
    
  3. in didDeselectRowAtIndexPath方法你可以得到回在節名

    func tableView(tableView: UITableView, didDeselectRowAtIndexPath indexPath: NSIndexPath) { 
        let section_name = self.sectionHeaderArray[indexPath.section] 
    } 
    

希望這會幫助你。

+0

嗨Ujesh,謝謝你的答案!我相信我不清楚自己想要什麼,下次我會在問題中加入一些代碼。我認爲你的解決方案可能會有效。但我以另一種方式做到了。骯髒的方式;)我在行中做了一個極端的UILabel,使該標籤不可見。然後分配給標籤上我在標題中使用的值。這樣我可以讀取didSelectRowAt中的值,並在下一個視圖中使用。 –

相關問題