我用约束做了一些简单的把戏。我制作了可扩展的 tableView
cell
。在 cell
上单击它会打开新单元格(黑色)(下图是为了更容易理解)。
我的问题是如何让它与顶部单元格内看起来像 “V” 的按钮一起使用。如果单击 cell
,我希望它至少旋转 90°。我怎样才能实现它。
我是这样扩展的:
override func tableView(tableView: UITableView, heightForRowAtIndexPath indexPath: NSIndexPath) -> CGFloat {
if(selectedIndex == indexPath.row){
return 210
}else{
return 135
}
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
if (selectedIndex == indexPath.row){
selectedIndex = -1
}else{
selectedIndex = indexPath.row
}
self.productstable.beginUpdates()
self.productstable.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.productstable.endUpdates()
}
最佳答案
可以使用闭包实现:
typealias arrowButtonTappedBlock = (button:UIButton) -> Void
在您的自定义单元格中声明一个闭包
,如下所示:
var arrowButtonTapped : arrowButtonTappedBlock!
然后在箭头按钮的点击操作上调用如下所示的闭包:
if arrowButtonTapped != nil {
arrowButtonTapped(button: sender as! UIButton)
}
并在 cellForRowAtIndexPath
中:设置闭包并执行您在 didSelectRowAtIndexPath:
cell!.arrowButtonTapped = { (button:UIButton) -> Void in
if (self.selectedIndex == indexPath.row){
self.selectedIndex = -1
}else{
self.selectedIndex = indexPath.row
}
self.tableview.beginUpdates()
self.tableview.reloadRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Automatic)
self.tableview.endUpdates()
}
关于ios - 单击按钮展开表格 View 单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39084817/