2014-10-17 75 views
3

我的單元格中有一個標籤,我想在點擊時顯示/隱藏。我知道我必須獲得從didSelectRowAtIndexPath中獲取的單元格的索引路徑。但我不確定如何在特定的單元格中顯示/隱藏標籤。當UITableView Cell被點擊時隱藏標籤

我可以在didSelectRowAtIndexPath之內顯示/隱藏它,還是有辦法在cellForRowAtIndexPath中處理它,然後更新它?

我做了一些研究,但我真的找不到很多。

這裏是我到目前爲止有:

var selectedRowIndex: NSIndexPath = NSIndexPath(forRow: -1, inSection: 0) 

override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) { 
    selectedRowIndex = indexPath 
} 
+0

您可以從'didSelectRowIndexPath'獲取單元格。 'UITableViewCell * cell = [tableView cellForRowAtIndexPath:indexPath];'並且隱藏這個單元格的標籤。 – Kampai 2014-10-17 12:47:10

回答

10

這裏是你如何從指數路徑到達小區:

let cell = tableView.cellForRowAtIndexPath(indexPath) as MyCustomCell 
cell.myTextLabel.hidden = true 

另外,根據您的需求,您可能希望取消選中該單元格。

tableView.deselectRowAtIndexPath(indexPath) 
+0

太棒了!我沒有意識到這很簡單。非常感謝。 – user3746428 2014-10-17 12:55:51