在 NSNotificationCenter 上放置断点
有什么办法可以打破 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用屏幕截图中显示的框在 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.
您可以在为特定事件调用的方法中放置断点。
例如
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
在这里,您可以在键盘事件发生时调用的keyboardWillShow和keyboardWillHide方法中使用断点。
因此,您需要指定有效的事件名称和有效的对象名称。
如果文本字段作为对象使用,
那么我认为您需要以正确的方式添加通知。
You can put break point in methods which you call for certain event.
e.g.
NSNotificationCenter *nc = [NSNotificationCenter defaultCenter];
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
so i think you need to add notification in right way.