I have added a feature to my app that allows users to add notes which will appear in table view cells when they are tapped as they expand to show more content.

My question is - How do I layout the content that is to be shown when the cell is expanded? I have tried adding the textView to the prototype cell, but I just get the textView overlapping on the other cells in the table view rather than being hidden before being tapped.

Here is my code for when a cell is tapped:

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

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

override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
    if indexPath.row == selectedRowIndex.row {
        if cellTapped == false {
            cellTapped = true
            return 141
        } else {
            cellTapped = false
            return 70
        }
    }
    return 70
}

Related posts

Recent Viewed