nsnotificationcenter

How to write Keyboard notifications in Swift 3

故事扮演 提交于 2019-11-30 02:25:20
I'm trying to update this code to swift 3: NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillShow:"), name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector("keyboardWillHide:"), name: UIKeyboardWillHideNotification, object: nil)` So far, I've just tried the auto corrections given by the compiler. This results in code like this: let notificationCenter = NotificationCenter.default() notificationCenter.addObserver(self, selector: Selector(("keyboardWillShow:")), name: NSNotification.Name

NSNotification order of observer notifications

橙三吉。 提交于 2019-11-30 00:27:58
问题 If I have several classes observing a particular NSNotification, in what order are the observers notified when the notification is posted? 回答1: There is no guarantee as to what order notifications are sent out. If you need an ordering you may want to create a class that listens for one notification and sends out multiple ordered notifications that other classes can listen for instead. 回答2: The order is undefined. Apple manages a list of observers and whenever the notification is posted, they

UI changes on background thread due to NSUserDefaultsDidChangeNotification

ⅰ亾dé卋堺 提交于 2019-11-29 23:48:54
问题 I am debugging an issue that occasionally causes my app to crash with a WebTryThreadLock message in the crash report. It looks like the app is crashing because the NSUserDefaultsDidChangeNotification is being sent and received on a background thread. I make UI changes when the notification is received and understand that making UI changes on a background thread is highly advised against. If NSUserDefaultsDidChangeNotification is sometimes (if not always) sent on a background thread, what is

How to pass a NSDictionary with postNotificationName:object:

余生颓废 提交于 2019-11-29 21:19:00
I am trying to pass an NSDictionary form a UIView to a UIViewController using NSNotificationCenter. The dictionary works fine at the time the notification is posted, but in the receiving method I am unable to access any of the objects in the dictionary. Here is how I am creating the dictionary and posting the notification... itemDetails = [[NSDictionary alloc] initWithObjectsAndKeys:@"Topic 1", @"HelpTopic", nil]; [[NSNotificationCenter defaultCenter] postNotificationName:@"HotSpotTouched" object:itemDetails]; In the UIViewController I am setting the observer... [[NSNotificationCenter

how to use the object property of NSNotificationcenter

坚强是说给别人听的谎言 提交于 2019-11-29 19:30:55
Could somebody please show me how to use the object property on NSNotifcationCenter. I want to be able to use it to pass an integer value to my selector method. This is how I have set up the notification listener in my UI View. Seeing as I want an integer value to be passed I'm not sure what to replace nil with. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveEvent:) name:@"myevent" object:nil]; - (void)receiveEvent:(NSNotification *)notification { // handle event NSLog(@"got event %@", notification); } I dispatch the notification from another class like this.

Android equivalent to NSNotificationCenter

╄→гoц情女王★ 提交于 2019-11-29 18:43:33
In the process of porting an iPhone application over to android, I am looking for the best way to communicate within the app. Intents seem to be the way to go, is this the best (only) option? NSUserDefaults seems much lighter weight than Intents do in both performance and coding. I should also add I have an application subclass for state, but I need to make another activity aware of an event. You could try this: http://developer.android.com/reference/java/util/Observer.html The best equivalent I found is LocalBroadcastManager which is part of the Android Support Package . From the

UIApplicationBackgroundRefreshStatusDidChangeNotification usage without corresponding delegate method

本小妞迷上赌 提交于 2019-11-29 15:23:16
问题 I feel that UIApplicationBackgroundRefreshStatusDidChangeNotification introduced in iOS 7 is of little use without supporting UIApplication delegate method. Because, the app is not notified when user has switch ON the background refresh state for my app. This is my notification handler... - (void)applicationDidChangeBackgroundRefreshStatus:(NSNotification *)notification { NSLog(@"applicationDidChangeBackgroundRefreshStatus with notification info = %@ and refresh status = %d", notification,

Swift 4 - Notification Center addObserver issue

大兔子大兔子 提交于 2019-11-29 12:27:19
问题 I'm crashing and getting an unrecognized selector error every time a Notification arrives and the App tries to execute its associated method. Here's my code - which is in viewDidLoad : let notificationCenter = NotificationCenter.default notificationCenter.addObserver(self, selector: Selector(("sayHello")), name:NSNotification.Name(rawValue: "dataDownloadCompleted"), object: nil) The sayHello() method is quite simple - looks like this: func sayHello() { print("Hello") } I've verified that the

NSUserNotificationCenter dismiss notification

为君一笑 提交于 2019-11-29 11:09:43
问题 I'm trying to use the new Mountain Lion NSUserNotificationCenter for my application (which isn't too hard actually). Posting notifications works like a charm via NSUserNotification *userNotification = [[NSUserNotification alloc] init]; userNotification.title = @"Some title"; userNotification.informativeText = @"Some text"; [[NSUserNotificationCenter defaultUserNotificationCenter] deliverNotification:userNotification]; However, i'd like to dismiss all notifications that are on the screen once

Removing a NSNotificationCenter observer in iOS 5 ARC

帅比萌擦擦* 提交于 2019-11-29 11:05:10
问题 I have an iOS 5 ARC-based project, and am having difficulty about where I should be removing the observer for the NSNotificationCenter observations which I have registered within a UIViewController . Similar posts on SO have said this should be done in the -dealloc method. Even though this method is not required in ARC projects I have added it with the following code: - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } As a test, I open the UIViewController (within