【问题标题】:can i Pass gesture recogniser in a notification我可以在通知中传递手势识别器吗
【发布时间】:2015-07-20 09:28:51
【问题描述】:

我正在从一个类向另一个类发送通知,以使用

调用方法
[[NSNotificationCenter defaultCenter]
     postNotification:[
                       NSNotification notificationWithName:@"gestureIsOn"
                       object: self
                       ]
     ];

我在这里想要实现的是在另一个类中接收通知,同时通过 UIGestureRecognizer 来查找它是哪个视图,因为接收通知的类包含 4 个不同的视图。我已经尝试实现这样的通知接收:

[[NSNotificationCenter defaultCenter ]addObserver:self
                                             selector:@selector(handleGestures::) name:@"gestureIsOn"
                                               object:nil];

并调用方法handleGestures:

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

if(sender.view == view1)
do something

}

尝试在我的观察者通知中使用双 :: 但这会导致错误 Terminating app due to uncaught exception 'NSInvalidArgumentException'

提前感谢所有花时间阅读本文的人。

【问题讨论】:

  • 你能粘贴更多关于这个的日志吗?
  • 我不能,因为我试图让问题保持简单并更改了我的类/变量名称以匹配问题

标签: ios objective-c notifications


【解决方案1】:

你可以这样发送:

[[NSNotificationCenter defaultCenter] postNotificationName:@"gestureIsOn"
                                                    object:self
                                                  userInfo:@{@"recognizer":recognizer}];

在接收方:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-03-17
    • 1970-01-01
    • 1970-01-01
    • 2012-12-15
    • 1970-01-01
    • 2014-01-24
    • 1970-01-01
    相关资源
    最近更新 更多