在 NSNotificationCenter 上放置断点

发布于 2024-10-12 06:57:44 字数 345 浏览 2 评论 0原文

有什么办法可以打破 NSNotificationCenter 发布具有特定名称的注释的情况吗?我有一个类由于某种原因没有收到预期的注释...

编辑澄清:

我已经为 MPMoviePlayerPlaybackDidFinishNotification 添加了一个观察者,但由于某种原因,似乎通知没有按预期发送。这里的一个正常错误是,我的对象由于某种原因取消了自己作为观察者的订阅(即使我发现该部分的代码看起来有效)。所以,我的意图是是否有可能打破 NSNotificationCenter 实际上传递某种类型的NotificationName,在本例中是 MPMoviePlayerPlaybackDidFinishNotification...

Is there any way to break on the NSNotificationCenter posting a Note with a certain name? I have a class that for some reason don't receive en expected note...

Edit for clarification:

I have added an observer for the MPMoviePlayerPlaybackDidFinishNotification, but for some reason it seems as if the Notification isn't sent as expected. A normal fault here is that my object for some reason has unsubscribed itself as an observer (even though I find my code on that part to look valid). So, my intention was whether or not it is possible to break on the NSNotificationCenter actually passing on a NotificationName of a certain type, in this case MPMoviePlayerPlaybackDidFinishNotification...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

得不到的就毁灭 2024-10-19 06:57:44

使用屏幕截图中显示的框在 Xcode 中添加一个名为“-[NSNotificationCenter postNotification:]”的断点。请记住,这将在发布每个通知时停止,因此您可能希望让调试器记录参数并自动继续。

Add a breakpoint in Xcode with the name "-[NSNotificationCenter postNotification:]" using the box displayed in the screenshot. Just remember that this will stop for every notification posted, so you might want to have the debugger log the arguments and autocontinue.

一页 2024-10-19 06:57:44

您可以在为特定事件调用的方法中放置断点。
例如

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

在这里,您可以在键盘事件发生时调用的keyboardWillShow和keyboardWillHide方法中使用断点。

因此,您需要指定有效的事件名称和有效的对象名称。

如果文本字段作为对象使用,

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserver:self
                       selector:@selector (handle_TextFieldTextChanged:)
                           name:UITextFieldTextDidChangeNotification
                         object:self.lockTextField];

那么我认为您需要以正确的方式添加通知。

You can put break point in methods which you call for certain event.
e.g.

NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];

[nc addObserver:self selector:@selector(keyboardWillShow:) name: UIKeyboardWillShowNotification object:nil];
[nc addObserver:self selector:@selector(keyboardWillHide:) name: UIKeyboardWillHideNotification object:nil];

here you can use break point in keyboardWillShow and keyboardWillHide method which call on the time of keyboard events.

So you need to specify valid event name and valid object name.

In case of textfield as an object you use like this

NSNotificationCenter *notificationCenter = [NSNotificationCenter defaultCenter];

[notificationCenter addObserver:self
                       selector:@selector (handle_TextFieldTextChanged:)
                           name:UITextFieldTextDidChangeNotification
                         object:self.lockTextField];

so i think you need to add notification in right way.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文