how to use the object property of NSNotificationcenter

The object parameter represents the sender of the notification, which is usually self. If you wish to pass along extra information, you need to use the NSNotificationCenter method postNotificationName:object:userInfo:, which takes an arbitrary dictionary of values (that you are free to define). The contents needs to be actual NSObject instances, not an integral type such … Read more

Posting NSNotification on the main thread

Yes you can. Generally you want the NSNotifications to be sent on the main , especially if they trigger UI activities like dismissing a modal login dialog. Delivering Notifications To Particular Threads Regular notification centers deliver notifications on the thread in which the notification was posted. Distributed notification centers deliver notifications on the main thread. … Read more

Android equivalent to NSNotificationCenter

The best equivalent I found is LocalBroadcastManager which is part of the Android Support Package. From the LocalBroadcastManager documentation: Helper to register for and send broadcasts of Intents to local objects within your process. This is has a number of advantages over sending global broadcasts with sendBroadcast(Intent): You know that the data you are broadcasting … Read more

How to pass object with NSNotificationCenter

You’ll have to use the “userInfo” variant and pass a NSDictionary object that contains the messageTotal integer: NSDictionary* userInfo = @{@”total”: @(messageTotal)}; NSNotificationCenter* nc = [NSNotificationCenter defaultCenter]; [nc postNotificationName:@”eRXReceived” object:self userInfo:userInfo]; On the receiving end you can access the userInfo dictionary as follows: -(void) receiveTestNotification:(NSNotification*)notification { if ([notification.name isEqualToString:@”TestNotification”]) { NSDictionary* userInfo = notification.userInfo; NSNumber* … Read more

How to pass data using NotificationCenter in swift 3.0 and NSNotificationCenter in swift 2.0?

Swift 2.0 Pass info using userInfo which is a optional Dictionary of type [NSObject : AnyObject]? let imageDataDict:[String: UIImage] = [“image”: image] // Post a notification NSNotificationCenter.defaultCenter().postNotificationName(notificationName, object: nil, userInfo: imageDataDict) // Register to receive notification in your class NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(self.showSpinningWheel(_:)), name: notificationName, object: nil) // handle notification func showSpinningWheel(notification: NSNotification) { if let … Read more

Move view with keyboard using Swift

Here is a solution, without handling the switch from one textField to another: override func viewDidLoad() { super.viewDidLoad() NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(“keyboardWillShow:”), name: UIKeyboardWillShowNotification, object: nil) NSNotificationCenter.defaultCenter().addObserver(self, selector: Selector(“keyboardWillHide:”), name: UIKeyboardWillHideNotification, object: nil) } func keyboardWillShow(notification: NSNotification) { if let keyboardSize = (notification.userInfo?[UIKeyboardFrameEndUserInfoKey] as? NSValue)?.CGRectValue() { self.view.frame.origin.y -= keyboardSize.height } } func keyboardWillHide(notification: NSNotification) { self.view.frame.origin.y … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)