Click event and button touch inside event

I have a table cell view with 4 UIButtons:

enter image description here

Buttons have a touch inside the event

@IBAction func increasDealRatingAction(sender:UIButton) {
    let buttonPosition = sender.convertPoint(CGPointZero, toView: self.tableView)
    if let indexPath = self.tableView.indexPathForRowAtPoint(buttonPosition) {
       ...
    }
}

And I have editing actions for each cell:

enter image description here

func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [UITableViewRowAction]? {
    ...
    return [addToWishListAction, addToPurchasesAction, deleteAction]
}

The problem is when you swipe left to show “add to wish list”, “delete” actions from the position of the “star” buttons, click on an event processed too, or a swipe action was not detected while scrolling through the button area.

0
source share
1 answer

Add gesture recognizer using buttons

let swipeGestureRecognizer = UISwipeGestureRecognizer(target: self, action: Selector("handleSwipes:")) // nil for selector is also possible
swipeGestureRecognizer.direction = .Left // Add this if you want only one direction
dealRatingButton.addGestureRecognizer(swipeGestureRecognizer)
// Add three star buttons

and impletment gestureRecognizer(_:shouldReceiveTouch:)to return false.

0
source

Source: https://habr.com/ru/post/1623274/


All Articles