iphone - Is it necessary to receive a NSNotification when adding an observer? -


here's thing..

every time see example around web related iphone - ipad dev, see every time controller register notification, callback method like:

-(void)mymethod:(nsnotification *)notification {     //bla bla } 

the same buttons actions.. like:

- (void)actionmethod:(id)sender {      //bla bla } 

i make tests, , method called anyway or without parameter. necessary? reason?

thanks !!!

from nsnotificationcenter doc:

notificationselector
selector specifies message receiver sends notificationobserver notify of notification posting. method specified notificationselector must have one , one argument (an instance of nsnotification).

[emphasis mine.]

you must provide selector correct signature; if don't, may work, may stop working when don't want to.

the reason might want notification can pass along information, in form of userinfo dictionary can specify when post notification using notificationwithname:object:userinfo:. can ignore argument when method called, parameter has there in method signature.

as buttons , actions, docs can have 1 of 3 signatures*:

the uikit framework allows 3 different forms of action selector:
- (void)action
- (void)action:(id)sender
- (void)action:(id)sender forevent:(uievent *)event

the ibaction return type equivalent void (there no return value), except presence in method in header allows interface builder know method intended action, can hook controls.

the reasons wanting button (or other control) similar of notifications. in case have many buttons in interface, of (such in table view) connect same action, may need distinguish exact things pressed button's identity.


*: completeness' sake, want mention not case on mac; there, action method must have form: - (ibaction)action:(id)sender.


Comments

Popular posts from this blog

php - What is the difference between $_SERVER['PATH_INFO'] and $_SERVER['ORIG_PATH_INFO']? -

fortran - Function return type mismatch -

queue - mq_receive: message too long -