我可以从这里告诉如何在objective-c中执行此操作,但是如何将其转换为swift?
我有一个带有自定义TableViewCells的UITableView,它有一个名为"expandButton"的UIButton.我试图找出如何在单击该单元格的expandButton时更改该特定单元格的高度.
此外,再次单击时,它应更改回原始大小.我不熟悉ObjectiveC所以请在Swift中帮助我.提前谢谢!
这是我到目前为止:
//Declaration of variables as suggested
var shouldCellBeExpanded:Bool = false
var indexOfExpendedCell:NSInteger = -1
Run Code Online (Sandbox Code Playgroud)
现在在ViewController里面.注意:TableViewCell是我的自定义单元格的名称.
//Inside the ViewController
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
if let cell:TableViewCell = TableViewCell() {
cell.stopWatch = stopWatchBlocks[indexPath.row]
cell.expandButton.tag = indexPath.row
//Adding action to the expand button
cell.expandButton.addTarget(self, action: "expandButtonAction1:", forControlEvents: UIControlEvents.TouchUpInside)
return cell
}
}
Run Code Online (Sandbox Code Playgroud)
现在,按钮动作方法:
func expandButtonAction1(button:UIButton) {
button.selected = !button.selected
if button.selected {
indexOfExpendedCell = button.tag
shouldCellBeExpanded = true
self.TableView.beginUpdates()
self.TableView.reloadRowsAtIndexPaths([NSIndexPath(forItem: indexOfExpendedCell, …Run Code Online (Sandbox Code Playgroud)