简体   繁体   中英

Hide label when UITableView Cell is tapped

I have a label within my cells that I would like to show/hide when tapped. I know that I have to get the index path of the cell that was tapped from within didSelectRowAtIndexPath . But I am unsure of how I then show/hide the label in that particular cell.

Am I able to show/hide it from within didSelectRowAtIndexPath , or is there a way to deal with it in cellForRowAtIndexPath and then update it?

I did some research into this but I really couldn't find a whole lot.

Here is all I have so far:

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

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

Here is how you get to the cell from the index path:

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

Also, depending on your needs, you might want to deselect the cell as well.

tableView.deselectRowAtIndexPath(indexPath)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM