如何增加和减少tableview单元格的rowheight?

时间:2017-11-30 07:30:07

标签: ios uitableview xcode8

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

1 个答案:

答案 0 :(得分:0)

用于展开和展开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
}

然后将此函数添加到viewcontroller

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

希望这会对你有所帮助

相关问题