Here is a quick and dirty example.
Say you have a restaurant with a name and he likes:
class Restaurant {
var name: String?
var likes: Int = 0
}
Restaurant dataSource. :
override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return self.dataSource.count
}
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Default, reuseIdentifier: "cell");
cell.textLabel?.text = dataSource[indexPath.row].name
return cell
}
override func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath) {
}
override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
let shareAction = UITableViewRowAction(style: .Default, title: "\(self.dataSource[indexPath.row].likes)") { (action, indexPath) -> Void in
self.dataSource[indexPath.row].likes++
self.tableView.setEditing(false, animated: true)
}
return [shareAction]
}
, , .
, , subviews UIButton . :
UITableViewCell ( ), , :
var cellRef: UITableViewCell?
override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell = UITableViewCell(style: .Default, reuseIdentifier: "cell");
cell.textLabel?.text = dataSource[indexPath.row].name
cellRef = cell;
return cell
}
share, subviews . UITableViewCellDeleteConfirmationView _UITableViewCellActionButton ( ).
let shareAction = UITableViewRowAction(style: .Default, title: "\(self.dataSource[indexPath.row].likes)") { (action, indexPath) -> Void in
var deleteConfirmationView: UIView?
if let subviews = self.cellRef?.subviews {
for subview in subviews {
if NSClassFromString("UITableViewCellDeleteConfirmationView") != nil {
if subview.isKindOfClass(NSClassFromString("UITableViewCellDeleteConfirmationView")!) {
deleteConfirmationView = subview
break
}
}
}
}
if let unwrappedDeleteView = deleteConfirmationView {
if unwrappedDeleteView.respondsToSelector("_actionButtons") {
let actionbuttons = unwrappedDeleteView.valueForKey("_actionButtons") as? [AnyObject]
if let actionButton = actionbuttons?.first as? UIButton {
actionButton.setTitle("newText", forState: .Normal)
}
}
}
}