0

I have a "Create Tribe" "button" in the header of a UITableView. It's not an UIButton, but 3 views ("+" icon, label, and a background view)

enter image description here

I have added a tap gesture recognizer to the background of the button (CreateTribeButton layer in the hierarchy).

enter image description here

The problem is, tapping on the button only works 1/3 of the time. I have to tap a few times in order for it to trigger the desired action.

I have no idea where I should begin debugging.

This view controller is embed in a pager - https://github.com/xmartlabs/XLPagerTabStrip

I have tried disabling the canCancelContentTouches and delaysContentTouches in the table view (which is actually a scroll view), and its parent pager's content view (which is also a scroll view). It doesn't actually solve the problem.

Is there an easy way for me to find out on which view did the touch get "eaten" up?

Cœur
  • 37,241
  • 25
  • 195
  • 267
kev
  • 1,085
  • 2
  • 10
  • 27
  • Maybe you don't want to hear this, but it would be much more simple if you'd just delete the hiararchy you have and created just one UIButton. UIButton has this cool features like setting image to left or right and setting all the alignments for the elements -> Content inset, image inset and title inset... – Dominik Bucher Feb 10 '18 at 13:22
  • Because now things getting reallz complicated when you have to create on your own the gesture recognizers and all this stuff and you have to handle if the tap isn't eaten with something else... Like from my point of view if you'd create even stackView with 2 buttons pointing to the same action it would be more efficient than this... – Dominik Bucher Feb 10 '18 at 13:23
  • @DominikBucher I forgot to mention. I've added a button, and it doesn't recognize any taps at all. – kev Feb 11 '18 at 05:01

1 Answers1

0

The easiest way to tell which section was tapped is in the

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath){} 

Function. You could simply implement

print(indexPath.row)

to find out what section was tapped. I would put a break point on this function and step through it. Additionally, you could programmatically call the buttons functionality when the right row is pressed. For example:

switch indexPath.row {
    case 0:
        doButton()
    case 1:
        /// do something else
    default:
        // break
    }

That will help you figure out what is going on.

Jake
  • 2,126
  • 1
  • 10
  • 23
  • This is not the section. It’s the header of the table. – kev Feb 10 '18 at 13:15
  • My mistake. I found a similar question here https://stackoverflow.com/questions/29274918/uitapgesture-in-uitableview-header – Jake Feb 10 '18 at 13:20
  • Set userInteractionEnabled = false for child layouts and check for the gesture event. – Pankaj Feb 10 '18 at 13:25