如何在iOS中为MGSwipeButton设置目标

如何在iOS中为MGSwipeButton设置目标,ios,uitableview,Ios,Uitableview,您好,我正在使用我的UITableview来刷卡我的手机。刷卡成功了。我在我的cellforrowatinex中添加了这些行,如下所示 //configure left buttons cell.leftButtons = @[[MGSwipeButton buttonWithTitle:@"Approve" icon:[UIImage imageNamed:@"approveTick"] backgroundColor:[UIColor colorWithRed:43.0/255 green

您好,我正在使用我的
UITableview
来刷卡我的手机。刷卡成功了。我在我的
cellforrowatinex
中添加了这些行,如下所示

 //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]]
                    ];

cell.rightSwipeSettings.transition=MGSwipeTransition3D;
现在我想为这两个按钮设置目标点击事件。但我不知道该怎么做。请帮我做这个。 谢谢

当您单击按钮时,此委托方法将调用。也不要忘记添加“MGSwipTableCellDelegate”


当您单击按钮时,此委托方法将调用。也不要忘记添加“MGSwipeTableCellDelegate”

为了侦听按钮单击事件,您可以实现可选的MGSwipeTableCellDelegate,或者如果您太懒了,MGSwipeButton类附带了一个方便的块回调;)

目标-c

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


为了侦听按钮单击事件,您可以实现可选的MGSwipTableCellDelegate,或者如果您太懒了,MGSwipeButton类附带了一个方便的块回调;)

目标-c

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


第一个答案是正确的 但对我来说,swift 3不适用于我,所以我决定与代表一起使用

这样做真的很容易。首先,我告诉我的学生,我要实现MGSwipeTableCell协议。我通过一个扩展来实现这一点:

extension ViewController: MGSwipeTableCellDelegate {
    func swipeTableCell(_ cell: MGSwipeTableCell!, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
        print("Button \(index) tapped")
        // here a switch to control the button tapped is a good choice
        return true
    }
}
第二:不要忘记在
func tableView(\utableview:UITableView,cellForRowAt indexPath:indexPath)->UITableViewCell中设置cell.delate


这是我的工作与Xcode 8和swift 3

根据中的说明,第一个答案是正确的 但对我来说,swift 3不适用于我,所以我决定与代表一起使用

这样做真的很容易。首先,我告诉我的学生,我要实现MGSwipeTableCell协议。我通过一个扩展来实现这一点:

extension ViewController: MGSwipeTableCellDelegate {
    func swipeTableCell(_ cell: MGSwipeTableCell!, tappedButtonAt index: Int, direction: MGSwipeDirection, fromExpansion: Bool) -> Bool {
        print("Button \(index) tapped")
        // here a switch to control the button tapped is a good choice
        return true
    }
}
第二:不要忘记在
func tableView(\utableview:UITableView,cellForRowAt indexPath:indexPath)->UITableViewCell中设置cell.delate


这是我的工作与Xcode 8和swift 3

你检查了我下面的答案了吗?你检查了我下面的答案了吗?我在tableview的cellForRowAt中添加了cell.delegate=self,并尝试调用此方法。此方法未在我的项目中调用。我还缺少什么吗?我在tableview的cellForRowAt中添加了cell.delegate=self,并尝试调用此方法。此方法未在我的项目中调用。我还缺什么吗?