nsnotificationcenter

NSNotificationCenter with respect to ViewWillAppear and ViewWillDisapper

不羁岁月 提交于 2019-12-19 10:25:22
问题 I have a simple viewController that I want to listen for UIKeyboardWillHideNotification . Therefore I have the following code: - (void) viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(keyboardWillBeHidden) name:UIKeyboardWillHideNotification object:nil]; } - (void) keyboardWillBeHidden { [self.scrollView setContentOffset:CGPointMake(0, 0) animated:YES]; } I'm trying to decide when to remove the

iOS remove notification from notification center [duplicate]

一个人想着一个人 提交于 2019-12-19 08:30:44
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: iOS application: how to clear notifications? is there a way how to remove notification from notification center(iOS 5) when I click it and start my application ? Thanks a lot 回答1: Set the applicationIconBadgeNumber property of your UIApplication instance to 0. That is, [UIApplication sharedApplication].applicationIconBadgeNumber = 0; Edit: In the current iOS SDK, you can't remove just a single notification from

Add 'addObserver' (NSNotificationCenter ) in a 1st view controller, handle in 2nd [duplicate]

女生的网名这么多〃 提交于 2019-12-19 06:19:14
问题 This question already has answers here : Send and receive messages through NSNotificationCenter in Objective-C? (6 answers) Closed 6 years ago . I saw a few examples about adding observer and handle in the same class, but what I want to know is if it's possible to add observer in first view controller and handle it in second view controller? I want constantly send distance from first view controller and handle it in the 2nd one. The 2nd view controller added as a sub view: addSubview ,

How to move content of UIViewController upwards as Keypad appears using Swift

孤街醉人 提交于 2019-12-19 05:01:35
问题 I want to move the content of the bottom of my UIViewController upwards as the keypad appears. At the bottom of the view controller I have a UITextField and when the user clicks it the keypad appears and blocks i,t so the user cannot see what they are inputting into the UITextField. I have the UITextField declared as follows: @IBOutlet var startTime : UITextField Would I need a UIScrollView to accomplish this? or is there a way to move the content of the page upwards as the keypad appears.

How to retrieve all NSNotificationCenter observers?

亡梦爱人 提交于 2019-12-18 19:09:08
问题 I'd like to retrieve a list of observers (objects and selectors) for a given notification name. I know there's no official API for that. I also know I could subclass NSNotificationCenter to accomplish this. Sometimes however this is not a viable option because NSNotificationCenter usage is spread all over the code or even binary frameworks. So I'm looking for an unofficial/private way to do this. (Since it's about debugging only, that's fine.) 回答1: Finally, Apple added a way to print all

Broadcast data to multiple widgets in Flutter

橙三吉。 提交于 2019-12-18 17:26:50
问题 Is there a way to broadcast data from one widget to other widgets? Similar to a BroadcastReceiver on Android or NSNotificationCenter on iOS. Specifically, I'm trying to detect when a Navigator pops or pushes a new view. I added navigatorObservers to MaterialApp. And when a widget comes back to the foreground, I want to be able to notify it by broadcasting changes from didPush and didPop with the actual route that's in the current foreground 回答1: Navigator.push returns a Future that will

CNContactStoreDidChangeNotification is fired multiple times

时间秒杀一切 提交于 2019-12-18 12:46:04
问题 I am able to observe the CNContactStoreDidChangeNotification when the contact database is changed while the app is in background state. I am pretty sure that only one observer was added to NSNotificationCenter . The problem is NSNotificationCenter posts MULTIPLE times (2, 3, 5, and even more times) even if I only add one new contact. Where is the problem? 回答1: Make certain you aren't adding the observer multiple times. This can happen without you realizing it if (for example) you call

Reachability network change event not firing

邮差的信 提交于 2019-12-18 11:43:11
问题 My iphone app is pretty simple with one view that handles everything, in viewDidLoad I check to see if we have an internet connection and if we do we load from the web and if not we load from a local resource. And this works fine. //in viewDidOnload [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleNetworkChange:) name:kReachabilityChangedNotification object:nil]; reachability = [Reachability reachabilityForInternetConnection]; [reachability startNotifier];

Post of NSNotificationCenter causing “EXC_BAD_ACCESS” exception

↘锁芯ラ 提交于 2019-12-18 10:58:15
问题 A UIViewController adds itself to the default center: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(editFood) name:@"editFood" object:nil]; Then a UITableView delegate NSObject posts a NSNotification : [[NSNotificationCenter defaultCenter] postNotificationName:@"editFood" object:self]; During run time it get a EXC_BAD_ACCESS exception. Is the defaultCenter getting released somewhere? The same concept works when I post a notification to a UIViewController from a

How to update UITableViewCells using NSTimer and NSNotificationCentre in Swift

随声附和 提交于 2019-12-18 10:46:22
问题 NOTE: Asking for answers in Swift please. What I'm trying to do: Have tableview cells update every 1 second and display a real-time countdown. How I'm doing it currently: I have a tableview with cells that contain a label. When the cells are generated, they call a function that calculates the time between today and a stored target date, and it displays the countdown time remaining in the label. To get the cells to update the label every second, I use an NSTimer that reloads the tableview