nsnotifications

Can I watch an NSNotification from another class?

荒凉一梦 提交于 2019-12-01 03:13:01
问题 I'm trying to get my head around NSNotificationCenter. If I have something like this in my App Delegate: [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(something:) name:@"something" object:nil]; ----- -(void)something:(NSNotification *) notification { // do something } Can I somehow watch this in another view controller? In my case, I'd like to watch it in a view controller with a table, and then reload the table when a notification is received. Is this possible?

How do I post a NSNotification when using Grand Central Dispatch?

三世轮回 提交于 2019-11-30 23:43:44
I found that as predicted when I was writing an image to file that my UI was blocked for the duration, which was not acceptable. When I write the image to file I then post an NS Notification so that I can do some other specific jobs related to that completion. Original working but UI blocking code: -(void)saveImageToFile { NSString *imagePath = [self photoFilePath]; BOOL jpgData = [UIImageJPEGRepresentation([[self captureManager] stillImage], 0.5) writeToFile:imagePath atomically:YES]; if (jpgData) { [[NSNotificationCenter defaultCenter] postNotificationName:kImageSavedSuccessfully object:self

Is there an NSNotification for phone call status

僤鯓⒐⒋嵵緔 提交于 2019-11-30 23:05:33
Is there an NSNotification we can observe for when the device is on/off the phone? The NotificationCenter doesn't send out any notifications abou this, but take a look at the CTCallCenter class introduced in iOS 4. It has a callEventHandler property that you can assign a block of code to, and gets called with call state info. There is a limitation in that the handler only gets called when your app is in the foreground (or being taken out of the foreground when a call comes in), but it tells you if the user is dialing ( CTCallStateDialing ), receiving a call ( CTCallStateIncoming ), answering

keyboardWillShow called twice

点点圈 提交于 2019-11-30 19:35:26
I have a view with keyboard notifications such as keyboardWillShow and keyboardWillHide All the codes handles with the notification I use is taken from Apple's sample code "KeyboardAccessory" When I first enter this view, everything works fine. But when I return to this view from its subviews, every time I tap a button that says: [myTextField becomeFirstResponder]; the keyboardWillShow and keyboardWillHide methods will be called twice every time. It's really confusing, Could anyone helps me with this? really appreciate! You might want to post your code. If your methods are being called twice,

Pass object with NSNotificationCenter to other view

∥☆過路亽.° 提交于 2019-11-30 19:27:42
I am trying to pass an object from my main view class to other notification receiver in another class. I want to pass an object named country, that loads all the cities from an SOAP Request in the Main Controller and i want to send it to my next view. country = [[Country alloc] init]; Country header: @interface Country : NSObject { NSString *name; NSMutableArray *cities; } @property (nonatomic,retain) NSString *name; - (void)addCity:(Cities *)city; - (NSArray *)getCities; - (int)citiesCount; @end I found a way to pass data with NSNotificatios is using a NSDictionary in UserInfo. But its not

NSNotifications in Swift 3

六月ゝ 毕业季﹏ 提交于 2019-11-30 13:38:21
Are the new notifications not currently working in Swift 3? I am doing: NotificationCenter.default().post(name: DidTouchParticleView, object: self.particle as? AnyObject) In a custom view's touchesBegan() and I need to send the particle object to the view controller if there is one. So I do this: NotificationCenter.default().addObserver(forName: DidTouchParticleView, object: self, queue: OperationQueue.main(), using: presentParticleDisplayView(notification:)) In a view controller's viewDidLoad() . I am certain that that particular view controller is the one presented when I tap my custom view,

NSNotificationCenter: Do objects receive notifications on the same thread they are posted?

ⅰ亾dé卋堺 提交于 2019-11-30 08:15:22
I am interested in knowing whether I can expect the observing object's method to be pushed onto the stack before the posting object's method has been completed and removed. Jarret Hardie The short answer is yes... "Regular notification centers deliver notifications on the thread in which the notification was posted. Distributed notification centers deliver notifications on the main thread". However, Apple has docs on this very subject that you may find helpful, and from which the above quote was pulled: Notification Programming Topics: Delivering Notifications to Particular Threads Just

keyboardWillShow called twice

独自空忆成欢 提交于 2019-11-30 03:03:29
问题 I have a view with keyboard notifications such as keyboardWillShow and keyboardWillHide All the codes handles with the notification I use is taken from Apple's sample code "KeyboardAccessory" When I first enter this view, everything works fine. But when I return to this view from its subviews, every time I tap a button that says: [myTextField becomeFirstResponder]; the keyboardWillShow and keyboardWillHide methods will be called twice every time. It's really confusing, Could anyone helps me

NSNotifications in Swift 3

与世无争的帅哥 提交于 2019-11-29 19:09:40
问题 Are the new notifications not currently working in Swift 3? I am doing: NotificationCenter.default().post(name: DidTouchParticleView, object: self.particle as? AnyObject) In a custom view's touchesBegan() and I need to send the particle object to the view controller if there is one. So I do this: NotificationCenter.default().addObserver(forName: DidTouchParticleView, object: self, queue: OperationQueue.main(), using: presentParticleDisplayView(notification:)) In a view controller's

NSNotificationCenter: Do objects receive notifications on the same thread they are posted?

大城市里の小女人 提交于 2019-11-29 11:17:50
问题 I am interested in knowing whether I can expect the observing object's method to be pushed onto the stack before the posting object's method has been completed and removed. 回答1: The short answer is yes... "Regular notification centers deliver notifications on the thread in which the notification was posted. Distributed notification centers deliver notifications on the main thread". However, Apple has docs on this very subject that you may find helpful, and from which the above quote was