当我们点击表视图单元格时它会扩展,但如果其他单元格已经展开,它们将不会崩溃意味着我们可以看到所有单元格一次扩展 .
我使用下面的代码进行单细胞扩展,但没有得到如何做多个细胞
override func tableView(tableView:UITableView,heightForRowAtIndexPath indexPath:NSIndexPath) - > CGFloat {
if indexPath.section == 2 && indexPath.row == selectedRowIndex && thereIsCellTapped {
switch indexPath.row{
case 0:
return 119
case 1:
return 93
case 2:
return 117
case 3:
return 135
case 4:
return 93
case 5:
return 230
default:
return 140
}
}
return 55
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
let currentCell = tableView.cellForRowAtIndexPath(indexPath) as! PatientDetailsTableViewCell
if indexPath.section == 2 {
self.tableView.cellForRowAtIndexPath(indexPath)?.backgroundColor = UIColor.whiteColor()
if self.selectedRowIndex != -1 {
self.tableView.cellForRowAtIndexPath(NSIndexPath(forRow: self.selectedRowIndex, inSection: 2))?.backgroundColor = UIColor.whiteColor()
}
if indexPath.section == 2 && selectedRowIndex != indexPath.row {
self.thereIsCellTapped = true
self.selectedRowIndex = indexPath.row
currentCell.lblRightArrow.text = "P"
print(selectedRowIndex)
}
else {
// there is no cell selected anymore
self.thereIsCellTapped = false
self.selectedRowIndex = -1
currentCell.lblRightArrow.text = "p"
}
self.tableView.beginUpdates()
self.tableView.endUpdates()
}
}
我使用该代码扩展单个单元格,但如何做多个单元格,我没有得到
请帮助....提前谢谢
2 回答
经过太多的工作,我得到了扩展多个细胞的解决方案,所以我在这里分享帮助别人..
对于扩展单元格,你必须在单击单元格时将indexPath存储在数组中,然后在tableview委托方法中使用该数组作为高度 . 我的代码如下 .
创建一个名为UITableViewController的TableViewController子类的新文件,并从storyboard中获取UITableViewController,并从Xcode的Identity Inspector中分配类TableViewController,并将单元标识符命名为“Cell” . 然后实现下面的类: