I want to expand the row height and show the content inside. I show my content in view I want when I tap on a cell it should expand like showed in the image
You don't even need to reload the cell, just get the current cell at the target location and modify it directly and call beginUpdates
and endUpdates
on the table view to have it recalculate all of the row heights.
You can adjust UITableView height and also manage reloading using below code
self.tableView.beginUpdates()
self.tableView.endUpdates()
You don't have to reload the whole table. UITableView
has a method func reloadRowsAtIndexPaths(indexPaths: [NSIndexPath], withRowAnimation animation: UITableViewRowAnimation)
. You can use this to update a single cell.
You can try with 2 custom cells. track user selection with variable and reload single cell with below code. when user click on cell load Detailed cell in cellForRowAtIndexPath
. your tableView
array should contain information which you are showing when cell is expended.
self.tableView?.beginUpdates()
var indexPath = NSIndexPath(forRow: rowNumber, inSection: 0)
self.tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Top)
self.tableView?.endUpdates()
Table height can only be changed through delegates there is no other way to do it i will show you a simple way to do it.
Declare variable
var selectedIndex = NSIndexPath()
Inside didSelectRowAtIndexPath reload selected cell
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
selectedIndex = indexPath
tableView.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade)
}
Inside heightForRowAtIndexPath return size
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if indexPath == selectedIndex {
return 100 //Size you want to increase to
}
return 50 // Default Size
}
Supposing that the logic to expand your TVC is working, you just need to call table view methods beginUpdates
and endUpdates
. Those method should wrap your update to the TVC.