Questions tagged [nsnotification]

NSNotification is a class used to send messages to observing classes through NSNotificationCenter.

NSNotification is a class used to send messages to observing classes through NSNotificationCenter. Notifications must have a name and can be optionally associated with a specific object. If an object is provided, the notification is only delivered to a class that is also observing the exact same name and object.

To send a notification, use NSNotificationCenter's postNotification: (a convenience function postNotificationName:object:userInfo: also exists which creates a notification and posts it with a single call). Classes posting a notification can also include an optional userInfo parameter to pass an object to the receiving class.

For more information, see Apple's documentation for NSNotification and NSNotificationCenter.

312 questions
9
votes
2 answers

How to detect MPMoviePlayerController starts a movie?

I am using MPMoviePlayerController, how do I detect when the movie actually started playing - as opposed to when the user fiddles with the seek controls? From the tests I made, I always get a "load state change" event and (moviePlayer.loadState ==…
9
votes
2 answers

Class method and instance method with the same name in Objective-C

I have a solution for a notification problem which works well, but I'm afraid might be a bad idea. I have a notification that needs to be handled by each instance of a class and by the class itself. To handle this, I'm registering for a notification…
Jeffery Thomas
  • 42,202
  • 8
  • 92
  • 117
8
votes
3 answers

iOS unable to remove Notification observer. Deinit not getting called

I have a UIView similar to the one you can see below: class ViewTaskViewController: UIViewController, UITableViewDataSource, UITableViewDelegate { override func viewDidLoad() { super.viewDidLoad() subscribeToNotifications() } func…
Sohil Pandya
  • 755
  • 1
  • 7
  • 19
8
votes
2 answers

How write unit test for receiving nsnotification asynchronous?

I call rest web servic with completion handler and if succeed I send NSNotification. The problem is how to write unit test to assert that the notification is sent in case of success. Any help will be appreciated.
Abdelrahman
  • 997
  • 2
  • 10
  • 24
8
votes
1 answer

NSNotificationCenter selector not being called

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…
indragie
  • 18,002
  • 16
  • 95
  • 164
8
votes
2 answers

KVO - How to get a list of an objects registered observers

I am registering an observer on a bunch of tableview controllers dynamically so I need to remove previous observers if they were registered on the same object. To do this I need to check if the observer exists on the object. Is this possible? I know…
7
votes
2 answers

NSNotificationCenter is calling multiple times

I have implemented NSNotificationCenter in my application. I send notification when ever image decoding is done. first time the image decoding will be done 8 times.So the notification suppose to send 8 times.But it is calling 64 times(8*8). Here is…
7
votes
3 answers

What's Difference between NSNotification 'object' and 'userInfo'?

What's difference between NSNotification's object and userInfo? When I post a notification with a parameter, I can use object or userInfos to do it. But I do not know what the difference is between these two ways. Is there some advantages to using…
saitjr
  • 159
  • 1
  • 9
7
votes
1 answer

Where to addObserver to NSNotificationcenter in a custom UITableViewCell?

In my UITableViewCell I have a method initNotification which is called by the TableViewController in cellForRowAtIndexPath where the TableCells are created. My Problem is that, every time this view is reloaded, the initNotification method is called…
user2071938
  • 2,055
  • 6
  • 28
  • 60
7
votes
2 answers

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

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…
Idan Moshe
  • 1,675
  • 4
  • 28
  • 65
6
votes
2 answers

NSNotification leads to segmentation fault

I have a strange behavior with an NSNotification object. My app has an navigation controller, first view is a table view and the second view is just a view controller which shows data of the selected cell. So in this data view controller I send a…
madmax
  • 1,803
  • 3
  • 25
  • 50
6
votes
3 answers

Observer in NSNotification (itemDidFinishPlaying) RANDOMLY to called twice

I am displaying a text as soon as a video is done playing. I am using a notification technique to achieve that. The only problem is that the Observer is called twice every now and then. It triggers the "itemDidFinishPlaying" twice (and therefore the…
Armand
  • 435
  • 1
  • 11
  • 23
5
votes
1 answer

How to prevent cheaters beating NSDate for iPhone games?

I'm currently playing around with NSNotification (or local notifications in general terms) for a product management game which relies heavily upon the user's NSDate/Time and then use local notifications to give an alert for when a product is…
zardon
  • 2,910
  • 6
  • 37
  • 58
5
votes
3 answers

Send NSNotification from classA to classB

So i have an app with an In App purchase. The In App purchase is managed in FirstViewController. When the user has purchased the product, i want to send out a Notification to my MainTableViewController to reload the tables data and show the new…
JonasG
  • 9,274
  • 12
  • 59
  • 88
5
votes
1 answer

Class as NSNotification observer?

Should it be possible to have a static NSNotification observer (like the code below)? I'm having some problems, and I think it may be due to my singleton class structure. I don't always have a class instance around to listen to the notifications,…
Dov
  • 15,530
  • 13
  • 76
  • 177
1
2
3
20 21