user1960169 user1960169 - 10 months ago 66
iOS Question

How to set target for MGSwipeButton in iOS

Hello I am using MGSwipeTableCell for my

in order to swipe my cells. Swiping is working. And I have added these lines in my
like below

//configure left buttons
cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"Approve" icon:[UIImage imageNamed:@"approveTick"] backgroundColor:[UIColor colorWithRed:43.0/255 green:178.0/255 blue:157.0/255 alpha:1.0]]

cell.leftSwipeSettings.transition = MGSwipeTransition3D;

//configure right button
cell.rightButtons=@[[MGSwipeButton buttonWithTitle:@"Reject" icon:[UIImage imageNamed:@"rejectDel"] backgroundColor:[UIColor colorWithRed:243.0/255 green:104.0/255 blue:97.0/255 alpha:1.0]]


Now I want to set target click events for those 2 buttons. But I don't understand properly how to do this. Please help me with this.

Answer Source

In order to listen for button click events you can implement the optional MGSwipeTableCellDelegate, or if you are too lazy to do that, the MGSwipeButton class comes with a convenience block callback ;)


[MGSwipeButton buttonWithTitle:@"More" backgroundColor:[UIColor lightGrayColor] callback:^BOOL(MGSwipeTableCell *sender) {
      NSLog(@"Convenience callback for swipe buttons!");


MGSwipeButton(title: "Delete", backgroundColor: UIColor.redColor(), callback: {
  (sender: MGSwipeTableCell!) -> Bool in
      println("Convenience callback for swipe buttons!")
      return true