在 swift 3.0 中,我想通过单击位于 UITableViewCell
的切换按钮操作来展开/折叠我的 UITableViewCell
高度。
最佳答案
在此函数中,您必须为 UITableView
行提供不同的高度:
func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat{
if(selectedIndexPath == indexPath){
return 200
}
return 60
}
注意:selectedIndexPath
为待展开单元格的索引路径。
您必须像这样在展开按钮上重新加载选定的单元格:
tableView.reloadRowsAtIndexPaths([selectedIndexPath!], withRowAnimation: .Fade)
或者为了获得更好的动画效果,您可以使用以下函数代替 tableView.reloadRowsAtIndexPaths
:
UIView.animateWithDuration(0.3, delay: 0.1, options: UIViewAnimationOptions.CurveEaseIn, animations: {
self.tableView.beginUpdates()
self.tableView.endUpdates()},completion:({ _ in
}))
关于ios - 单击切换按钮展开/折叠 UITableViewCell 高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41712827/