How to increase the single row height without reloading UITableView or individual cells [Swift]?

前端 未结 6 635

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

6条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-17 18:13

    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
    }
    

提交回复
热议问题