-1

I have a table where a gesturerecognizer should be added to the table-header-label. This is done through following code:

    UITapGestureRecognizer *singleFingerTap =
    [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(handleTableheaderTap:)];
    [headerView addGestureRecognizer:singleFingerTap];
    singleFingerTap.delegate = self;

The selector-method looks like following:

- (void)handleTableheaderTap:(UITapGestureRecognizer *)recognizer

Unfortunately, the recognizer is nil, when the method is called. What do I have to change, so the recognizer is in the handletTableheaderTap not nil anymore?

Thank you!

David Snabel-Caunt
  • 57,804
  • 13
  • 114
  • 132
m1h
  • 21
  • 6
  • 1
    How exactly are you determining that "the recognizer is nil when the method is called"? –  Sep 04 '14 at 12:11

1 Answers1

0

You have to store the instance in a controller attribute. Declare a private property to store it.

Example :

@interface MyViewController()
@property (nonatomic, strong) UITapGestureRecognizer *singleFingerTap
@end

...

self.singleFingerTap = [[UITapGestureRecognizer alloc] initWithTarget:self
                                            action:@selector(handleTableheaderTap:)];
 [headerView addGestureRecognizer:singleFingerTap];
  singleFingerTap.delegate = self;
David Ansermot
  • 6,052
  • 8
  • 47
  • 82