nsnotificationcenter

Use NSNotificationCenter selector for one observer in multiple view controllers

和自甴很熟 提交于 2019-12-02 08:46:45
Can I use the selector getUpdate: in multiple view controllers? I'm registering my LevelViewController as an observer for both GameViewController and WinViewController . The latter 2 view controllers both have a back button (which, when pressed, pops you back to LevelVC ), and the idea with the notification is to tell LevelVC whether or not to update the collection view cells (via the viewWillAppear: method) when the back button is pressed. In viewWillAppear: , I wouldn't want to call two separate methods (one from GameVC and one from WinVC ) in order to get my update, I just one fluid method

Main Thread Runloop gets blocked on opening nsmenu

房东的猫 提交于 2019-12-01 23:46:59
I have an application for which the UI element includes an NSStatusItem and a menu. Inside my application , I am using NSTask asynchronously to perform some operation and I am using the output obtained using the NSFileHandleReadCompletionNotification to update the menu. But now whenever I click and open the menu , the main runloop goes into NSEventTrackingRunLoopMode and the notification posting fails. So basically with my menu open , no operation takes place on the main thread. Now I found a similar problem on this post but the accepted solution there does not seem to help. I understand that

keyboardWillShow gets called for other app's keyboards

冷暖自知 提交于 2019-12-01 16:49:56
I know this is what's supposed to happen, but it's causing me problems that I don't know how to fix. I want to move my view up when the keyboard shows, so that my text fields remain visible. My text fields have numeric keypads. I use notifications and keyboardWillShow/Hide to move my view up/down when a text field is selected. Now suppose I tap on a text field and then switch to another app that's using a different keyboard (not the numeric keypad). keyboardWillShow is called with the size of the wrong keyboard (the one from the other app) and my view is moved the wrong amount (it shouldn't

keyboardWillShow gets called for other app's keyboards

跟風遠走 提交于 2019-12-01 16:05:11
问题 I know this is what's supposed to happen, but it's causing me problems that I don't know how to fix. I want to move my view up when the keyboard shows, so that my text fields remain visible. My text fields have numeric keypads. I use notifications and keyboardWillShow/Hide to move my view up/down when a text field is selected. Now suppose I tap on a text field and then switch to another app that's using a different keyboard (not the numeric keypad). keyboardWillShow is called with the size of

why do I get “wait_fences: failed to receive reply” for this code?

[亡魂溺海] 提交于 2019-12-01 11:05:10
why do I get "wait_fences: failed to receive reply" for this code? Is it the way I'm using notification to communicate back to the main thread? #import "ViewController.h" @implementation ViewController @synthesize alert; #pragma mark - Background Thread Test Methods - (void) ConfigTasksForBackground:(id)sender{ NSLog(@"ConfigTasksForBackground - Starting"); [NSThread sleepForTimeInterval:6]; [[NSNotificationCenter defaultCenter] postNotificationName:@"ModelChanged" object:self]; NSLog(@"ConfigTasksForBackground - Ending"); } #pragma mark - Callbacks - (void) ModelChangedHandler:(NSNotification

Giving notification to another class with NSNotificationCenter

拟墨画扇 提交于 2019-12-01 07:09:17
问题 So my goal is to deliver a notification to another class with using NSNotificationCenter , I also want to pass object with the notification to the other class , how should I do this? 回答1: You must first register a notification name [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(startLocating:) name:@"ForceUpdateLocation" object:nil]; // don't forget the ":" And then post a notification with a dictionary of parameters [[NSNotificationCenter defaultCenter]

How to add an observer to NSNotificationCenter in a C++ class using Objective-C++?

回眸只為那壹抹淺笑 提交于 2019-12-01 07:03:33
Hey guys I have a C++ class that I recently renamed from *.cpp to *.mm to support objective-c. So I can add the following objective-c code. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(notificationHandler:) name:@"notify" object:nil]; How do/Can I write the notificationHandler method in c++? Will setting addObserver:self property work? You'd need an Objective-C class to handle Objective-C notifications. Core Foundation to the rescue! In.. wherever you start listening for notifications, e.g. your constructor: static void notificationHandler(CFNotificationCenterRef

Can I watch an NSNotification from another class?

耗尽温柔 提交于 2019-12-01 05:24:43
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? Yes you can that is the whole purpose of NSNotification , you just have to add the View Controller you

Rapid row insertion into UITableView causes NSInternalInconsistencyException

僤鯓⒐⒋嵵緔 提交于 2019-12-01 05:24:01
问题 I have a UITableView that sometimes has rapid insertions of new rows. The insertion of the new rows is handled by a notification observer listening for the update notification fired whenever the underlying data changes. I use a @synchronized block around all the data model changes and the actual notification post itself... hoping that each incremental data change (and row insertion) will be handled separately. However, there are times when this still fails. The exception will tell me that it

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?