我四处寻找其他答案,但似乎没有任何效果。我已经实现了这段代码:
var selectedCellIndexPath: NSIndexPath?
let selectedCellHeight: CGFloat = 88.0
let unselectedCellHeight: CGFloat = 51.0
// Override to support editing of individual itemCells
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if selectedCellHeight == indexPath {
return selectedCellHeight
}
return unselectedCellHeight
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if selectedCellIndexPath != nil && selectedCellIndexPath == indexPath {
self.selectedCellIndexPath = nil
} else {
self.selectedCellIndexPath = indexPath
}
tableView.beginUpdates()
tableView.endUpdates()
if selectedCellIndexPath != nil {
// THis ensure, that the cell is full visile once expended
tableView.scrollToRowAtIndexPath(indexPath, atScrollPosition: .None, animated: true)
}
}
我从其他 StackOverFlow 答案中得到它,但是当我运行我的应用程序时,单元格仅显示它已被选中(通过着色),然后不执行任何其他操作。任何帮助都会很棒!我是初学者!
最佳答案
if selectedCellHeight == indexPath {
应该是
if selectedCellIndexPath == indexPath {
关于ios - 选中单元格时如何更改单元格的高度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36226368/