The code below works, but probably the best way. My goal is to call the UIViewController function from the UITableCell when exiting edit mode.
I do this by setting an instance of the UIViewController link to each UITableViewCell, and then I call the CancelDelete () function to change the state of the UITableViewCell.
The code seems inefficient because for each MyCell I first create an instance of MyViewContoller as a public variable, and then replace it with a link to the UIViewController when I initialize the UITableView.
Is there a better way to do this?
class MyCell : UITableViewCell
{
var previousState : UITableViewCellStateMask = UITableViewCellStateMask.allZeros
var controller:MyViewController = MyViewController()
override func willTransitionToState(state: UITableViewCellStateMask) {
if state & UITableViewCellStateMask.ShowingEditControlMask != nil {
if previousState & UITableViewCellStateMask.ShowingDeleteConfirmationMask != nil {
controller.CancelDelete(self)
}
}
previousState = state
}
}
class MyViewController: UIViewController, UITableViewDataSource, UITableViewDelegate {
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:MyCell = tableView.dequeueReusableCellWithIdentifier("cell") as MyCell
cell.controller = self
cell.tag = indexPath.row
}
func CancelDelete(cell:MyCell) {
editButtons[cell.tag].hidden = false
}
}
billd source
share