In all the tutorials or examples I find, they show a colon after the selector name (getCurrentData:), like so:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(getCurrentData:)
name:@"mapsReceived"
object:nil ];
Since there is nothing after this colon in the examples, I assume that the method specified does not take any arguments. And mine doesn’t either, but when I use the above syntax my app crashes and says unrecognized selector sent to instance I remove the colon, and it works. So why do all examples show a colon?
Secondly, if I did use a selector that required an argument, how can I do that? If I do this:
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(createButtons:@"ten grand";)
name:@"mapsReceived"
object:nil ];
It won’t even compile; I get tons of errors until I remove the text string and the colon. Yet I can call this method, with the string, just fine when using it outside NSNotification. Is there a way to do what I want here?
First, most all examples assume that you are passing the notification to the method. For example:
This would be represented as:
If you removed this argument, it would be
As for the second item, you cannot specify arguments in that manner. You need to architect your methods in such a way that it receives the notification as the argument, and then you can inspect the notification and call another method to perform whatever action you need.