nsnotificationcenter

Instance was deallocated while key value observers were still registered with it

南笙酒味 提交于 2019-12-04 17:40:25
问题 I've got a UITableView. Here I got different cell's. Each cell has a model. With KVO and NotificationCenter the cell listen to the model for changes. When I leave the ViewController I get this error: An instance 0x109564200 of class Model was deallocated while key value observers were still registered with it. Observation info was leaked, and may even become mistakenly attached to some other object. Set a breakpoint on NSKVODeallocateBreak to stop here in the debugger. Here's the current

iphone notification results in “unrecognized selector sent to instance…”

时光总嘲笑我的痴心妄想 提交于 2019-12-04 17:09:50
问题 To make it short, I'm registering the following NSNotification listener in ClassA (in viewDidLoad ): [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(playSong) name:@"playNotification" object:nil]; I have the selector declared in ClassA.h : - (void)playSong:(NSNotification *) notification; And implementation goes as follows: - (void)playSong:(NSNotification *) notification { NSString *theTitle = [notification object]; NSLog(@"Play stuff", theTitle); } In ClassB (in

is removeObserver necessary on dealloc?

旧街凉风 提交于 2019-12-04 14:19:32
In one of my view controller, it adds itself as observer of UITextViewTextDidEndEditingNotification notification, like the following does [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(done:) name:UITextViewTextDidEndEditingNotification object:nil]; Now I am wondering - do I need to do the following when the view controller is dealloc'd [[NSNotificationCenter defaultCenter] removeObserver:self]; yes, you should always remove any observers when they're being dealloc'd. otherwise the notification center will keep references to the now-dealloc'd objects around and

removeObserver not working

ε祈祈猫儿з 提交于 2019-12-04 13:53:10
问题 I have next code: @implementation SplashViewVC - (void)viewDidLoad { [super viewDidLoad]; self.splashView.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"Default.png"]]; self.activityIndicator.originY = 355.f; [[NSNotificationCenter defaultCenter] addObserverForName:NCDownloadComplete object:nil queue:[NSOperationQueue mainQueue] usingBlock:^(NSNotification *n){ NSInteger errorCode = [n.userInfo[@"errorCode"] integerValue]; [self.activityIndicator stopAnimating]; if

Mac OS X - How to monitor a window change event?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 10:04:22
I'm developing a Cocoa application that shows a list of opened windows and highlights the current focused one. My problem is that I can't find a system notification to inform my app that the main (aka "focused" or "foreground") window has changed. I tried with: [[[NSWorkspace sharedWorkspace] notificationCenter] addObserver:self selector:@selector(wsNotificationHook:) name:NSWorkspaceDidActivateApplicationNotification object:nil]; but it monitors APPLICATION change: it isn't get fired when a change of window is executed INSIDE the same application (for example, if I pass between two Firefox

Refreshing Parent ViewController after dismissing ModalViewController

余生颓废 提交于 2019-12-04 07:59:48
问题 In my iOS app, a user can select an image from a list, upon which they are presented with a modal that contains the image and options to delete the image. If the user chooses to delete the image, she is returned to the original viewController containing the list of images. I need to then refresh the original ViewController to take into account the deleted image. I tried using NSNotificationCenter to broadcast when an image is deleted to the parent View Controller. However, it seems like the

UIKeyboard Suggestions height for iOS 8 notification?

坚强是说给别人听的谎言 提交于 2019-12-04 06:40:44
I'm trying to keep a text field sitting atop the keyboard in iOS 8. But when a user swipes up or down the top of the keyboard to show or dismiss iOS 8 word suggestions, I need to a notification of the new height of the keyboard so I can move my text field up or down by that height. How can I accomplish this? Thanks! You can register for UIKeyboardDidShowNotification and then get the keyboard frame from the notification with UIKeyboardFrameEndUserInfoKey. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleKeyboardDidShowNotification:) name

Why does EAAccessoryDidConnectNotification occur twice?

混江龙づ霸主 提交于 2019-12-04 05:11:19
I have a class that manages messages coming from and going to an external accessory to an iPad. In the init I have the following code: - (id) init { self = [super init]; if (!self) return; [[EAAccessoryManager sharedAccessoryManager] registerForLocalNotifications]; //we want to hear about accessories connecting and disconnecting [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidConnect:) name:EAAccessoryDidConnectNotification object:nil]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(accessoryDidDisconnect:) name

View controller dealloc not called when using NSNotificationCenter code block method with ARC

强颜欢笑 提交于 2019-12-04 04:58:30
When I use -addObserverForName: object: queue: usingBlock: for NSNotificationCenter in the -viewDidLoad: method of my view controller, the -dealloc method ends up not being called. (When I remove -addObserverForName: object: queue: usingBlock: , -dealloc is called again.) Using -addObserver: selector: name: object: doesn't seem to have this problem. What am I doing wrong? (My project is using ARC.) Below is an example of my implementation, in case I'm doing something wrong here: [[NSNotificationCenter defaultCenter] addObserverForName:@"Update result" object:nil queue:nil usingBlock:^

KVO versus NSNotifications [duplicate]

泄露秘密 提交于 2019-12-04 03:07:27
This question already has an answer here: NSNotification VS KVO 1 answer Is there any advantage to use KVO instead of the more "generic" (and to my opion more robust) feature of NSNotification s ? I hate KVO with passion, mainly because it forces me to route all KVO notifications through a single handler. I use whatever else available if I have the choice. But KVO has the distinct advantage of being available for many of the classes in the standard library – if you want to observe property changes on some classes from the standard library, KVO might be your only option. There is one very