[英]multiple clicks on custom tableViewCell
I have a custom tableView cell, When I click on the cell the height of the cell increases (the cell expands): 我有一个自定义的tableView单元格,当我单击该单元格时,该单元格的高度会增加(该单元格会展开):
var selectedIndex:IndexPath?
var isExpanded = false
func didExpandCell(){
self.isExpanded = !isExpanded
self.TableView.reloadRows(at: [selectedIndex!], with: .automatic)
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
self.selectedIndex = indexPath
self.didExpandCell()
}
I would like to click the cell a second time and segue to another view controller; 我想再次单击该单元格,然后选择另一个视图控制器; is this possible? 这可能吗?
self.performSegue(withIdentifier: "details", sender: tableView)
In the func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
method you have to check whether the cell is expanded or not. 在func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath)
方法中,您必须检查单元格是否已扩展。 If it is expanded try calling self.performSegue(withIdentifier: "details", sender: tableView)
. 如果扩展,请尝试调用self.performSegue(withIdentifier: "details", sender: tableView)
。 If it is not then implement the code to expand the cell. 如果不是,则实施代码以扩展单元格。
This is a different way other than checking for isExpanded
state: 这与检查isExpanded
状态不同:
In didSelectRowAt
, put a condition to check whether selected cell's height is equal to the expanded cell height (For ex., if the expanded cell height is set to 100 static). 在didSelectRowAt
,放置一个条件来检查选定单元格的高度是否等于扩展单元格的高度(例如,如果扩展单元格的高度设置为100静态)。 If YES
, then call performSegue
如果YES
,则调用performSegue
The following is just a pseudocode for the logic: 以下只是逻辑的伪代码:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let cell = getCellForIndexPath(indexPath)
if cell.frame.size.height == 100 { // 100 is assumed to be static height for expanded cell. If it is dynamic, compare with normal cell height
performSegue()
} else {
self.didExpandCell()
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.