nsnotificationcenter

NSNotificationCenter selector not being called

て烟熏妆下的殇ゞ 提交于 2019-12-01 02:50:44
问题 In my iPad app, in one class I register for a notification: NSNotificationCenter *nc = [NSNotificationCenter defaultCenter]; [nc addObserver:self selector:@selector(selectedList:) name:@"TTSelectedList" object:nil]; My selectedList: method looks like this: - (void)selectedList:(NSNotification*)notification { NSLog(@"received notification"); } Then in another class (a UITableViewController ) I post that notification when a row is selected: - (void)tableView:(UITableView *)tableView

NSNotification postNotificationName in AppDelegate but NSNotificationCenter in ViewController?

蹲街弑〆低调 提交于 2019-12-01 00:54:32
I can't get the selector method, receiveChatText, in the NSNotificationCenter to execute and I am wondering if the problem is because the NSNotification postNotificationName is in AppDelegate.m but NSNotificationCenter is in ViewController.m? I.E. can the postNotificationName know that the NSNotificationCenter is in another viewController file or is that something I need to tell it? In a viewController.m I have -(id)init { self = [super init]; if(self){ [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(receiveChatText:) name:ChatMessageReceived object:nil]; return self;

Is there a change to the behaviour of UIKeyboardWillShowNotification in iOS 8?

可紊 提交于 2019-12-01 00:24:42
I have had a simple UIView block animation that handles animating a group of text fields into view when the keyboard will show (and animate them back when the keyboard hides). This has worked fine in iOS 6 & 7, but now I'm getting incorrect behavior, and it all points to some change in UIKeyboardWillShowNotification . I set up an isolated project to test this further on a single text field, with two buttons that call exactly the same methods that are fired for the keyboard's WillShow and WillHide notifications. See the results in this video: Video example This seems like a bug to me, or it

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

How to retrieve all NSNotificationCenter observers?

我是研究僧i 提交于 2019-11-30 18:28:57
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.) Finally, Apple added a way to print all notification center observers: po [NSNotificationCenter defaultCenter] It prints a comma separated list with

How do I check if an UIViewController is currently being displayed?

房东的猫 提交于 2019-11-30 17:46:29
How do I check if an UIViewController is currently being displayed? My UIViewControllers are listening for NSNotifications - even if when they are not displayed (ie not shown). So I could have 10 UIViewController in the background observing NSNotifications from NSNotificationCenter . When an NSNotification is posted and received by the UIViewController , I'd like to find out if it is currently being shown. If it is not, I will just set a boolean so that it will processed when the View is presented. If it currently being display, I will do more things like update tables immediately, and so

NSNotification order of observer notifications

左心房为你撑大大i 提交于 2019-11-30 17:08:57
If I have several classes observing a particular NSNotification, in what order are the observers notified when the notification is posted? 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. The order is undefined. Apple manages a list of observers and whenever the notification is posted, they iterate over the list and notify every registered observer. The list may be an array or a dictionary or something

How do I check if an UIViewController is currently being displayed?

烂漫一生 提交于 2019-11-30 16:40:15
问题 How do I check if an UIViewController is currently being displayed? My UIViewControllers are listening for NSNotifications - even if when they are not displayed (ie not shown). So I could have 10 UIViewController in the background observing NSNotifications from NSNotificationCenter . When an NSNotification is posted and received by the UIViewController , I'd like to find out if it is currently being shown. If it is not, I will just set a boolean so that it will processed when the View is

UI changes on background thread due to NSUserDefaultsDidChangeNotification

元气小坏坏 提交于 2019-11-30 16:34:11
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 the best way to handle this? Something like the following seems excessive but potentially necessary. [

NSNotification is being called multiple times from UITabBarController

谁说胖子不能爱 提交于 2019-11-30 16:12:54
问题 I have a UITabBarController , which has 4 tabs. Each one of those tabs is a separate UIViewController . I have objects on each one of those 4 VC's that use NSNotification 's to perform actions upon the press of a certain object. The 4 VC's all respond to the notification in the same way because it is a similar object on each page. When this object is pressed it presents a view onto the current view controller. The problem is that if I move to any of the other 3 tabs now that view is also on