CAN I PASS GESTURE RECOGNISER IN A NOTIFICATION

naomi burke

Total Post:28

Points:196
Posted by  naomi burke
 755  View(s)
Ratings:
Rate this:

I am sending a notification from one class to another to call a method using

[[NSNotificationCenter defaultCenter] postNotification:

[NSNotification notificationWithName:@"gestureIsOn" object: self ]];

WhatI want to achieve here is to receive the notification in another class but also passing the UIGestureRecognizer to find which view it is, as the class receiving the notification contains 4 different views. I already tried to implement the receiving of the notification like this:

[[NSNotificationCenter defaultCenter] addObserver:self

                                             selector:@selector(handleGestures::) name:@"gestureIsOn"

                                             object:nil ];

and call the method handleGestures:

-(void)handleGestures:(UIGestureRecognizer *)sender :(NSNotification *)notification { 

if(sender.view == view1)

do something

}

Tried to use double :: in my observer notification but this causing an error of Terminating app due to uncaught exception 'NSInvalidArgumentException'

Thanks in advance to everyone that spend time reading this.

  1. Tarun Kumar

    Post:214

    Points:1642
    Re: can i Pass gesture recogniser in a notification

    You could send it like this:

    [[NSNotificationCenter defaultCenter] postNotificationName:@"gestureIsOn"

                                                      object:self

                                                      userInfo:@{@"recognizer":recognizer}];

    And on the receiving side:

    UIGestureRecognizer *recognizer = notification.userInfo[@"recognizer"];

     

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!