单击切换按钮展开/折叠UITableViewCell高度

时间:2017-01-18 06:34:55

标签: ios swift uitableview

我希望在点击位于UITableViewCell swift 3.0中的切换按钮操作时展开/折叠UITableViewCell高度。

1 个答案:

答案 0 :(得分:2)

您必须在此功能中为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
  }))
相关问题