开发者

Place a breakpoint on the NSNotificationCenter

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 reas开发者_JAVA技巧on 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...


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.

Place a breakpoint on the NSNotificationCenter


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜