Home > DeveloperSection > Forums > can i Pass gesture recogniser in a notification
naomi burke
naomi burke

Total Post:28

Points:196
Posted on    July-20-2015 3:43 AM

 iPhone iPhone  Ios  Objective C 
Ratings:


 1 Reply(s)
 486  View(s)
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.



Tarun Kumar

Total Post:213

Points:1635
Posted on    July-20-2015 8:16 AM

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

 


Don't want to miss updates? Please click the below button!

Follow MindStick