【问题标题】:How to increase and decrease rowheight of tableview cell?如何增加和减少表格视图单元格的行高?
【发布时间】:2017-11-30 07:30:07
【问题描述】:

我有带问题视图的表格视图单元格,每个问题包含三个选项注释视图、图像视图和操作项视图。一个单元格包含更多按钮。使用这个更多按钮,我必须(显示/隐藏)注释视图、图像视图、操作项视图,默认情况下单元格加载问题视图。

【问题讨论】:

标签: ios uitableview xcode8


【解决方案1】:

用于展开和折叠tableviewcell

var selectedIndex = "" 

在您的viewDidLoad 中添加以下行

tableView.rowHeight = UITableViewAutomaticDimension
tableView.estimatedRowHeight = 300 //give maximumheight you expect in tableviewcell

将NotesView高度约束出口设置为UITableViewCell

将此行添加到您的cellForRowAt

cell.moreBtn.tag = indexPath.row
cell.moreBtn.addTarget(self, action: #selector(self.moreClicked(_:)), for: .touchUpInside)

if selectedIndex == "\(indexPath.row)" {
cell.notesViewHgt.constant = 100 //give height you required
} else {
cell.noteViewHgt.constant = 0
}

然后将此函数添加到您的视图控制器中

func moreClicked(_ sender:UIButton){
self.selectedIndex = "\(sender.tag)"
self.tableView.reloadData()
}

希望对你有帮助

【讨论】:

  • 如果您认为您的问题已解决,您可以接受答案,这会将问题标记为已回答。干杯!
猜你喜欢
  • 2021-01-21
  • 1970-01-01
  • 2020-04-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多