gpt4 book ai didi

ios - 我可以在通知中传递手势识别器吗

转载 作者:行者123 更新时间:2023-11-29 01:50:02 24 4
gpt4 key购买 nike

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

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

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

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

并调用方法handleGestures:

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

if(sender.view == view1)
do something

}

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

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

最佳答案

你可以这样发送:

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

在接收方:

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

关于ios - 我可以在通知中传递手势识别器吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31513005/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com