Different classes will have different delivery methods, and the parameter names may vary. If it is a flyer parameter is not set, if it is passed multiple parameters can be used similar to a collection of nsarray,nsdictionary. Look at the following example:
Example 1:
Through Nstimer to see how the iphone functions to @selector the parameters,
Nsmutabledictionary *dict =[[Nsmutabledictionary alloc] init]; if(Oldview! =Nil) {[Dict setobject:oldview forkey:@"Oldview"]; } if(Newview! =Nil) {[Dict setobject:newview forkey:@"Newview"]; } [Nstimer Scheduledtimerwithtimeinterval:0.0target:self selector: @selector (onTimer:) userinfo:dict Repeats:no]; [Dict release]; - (void) OnTimer: (Nstimer *) Timer {UIView*oldview = [[Timer userInfo] Objectforkey:@"Oldview"]; UIView*newview = [[Timer userInfo] Objectforkey:@"Newview"]; [UIView animatewithduration:2.0Delay0options:uiviewanimationoptionallowuserinteraction Animations:^{Oldview.alpha=0.0; Newview.alpha=1.0; } }
As can be seen,Nstimer in the @selector (onTimer:) to pass parameters, the object of the argument is stored in the nstimer userinfo Dictionary, in-(void) OnTimer: (Nstimer *) in timer
be used by removing the dictionary.
Example 2:
-(void) Addnotifications: (nsarray*) data{ if (data==nil| | data.count!=2) { return; } NSString string to Nsinteger Nsinteger notifynum=[(nsstring*) data[0] intvalue]; Nsinteger index=[data[1] intvalue]; Mynbtabbutton *button=_buttondata[index]; [Button.light addnotifications:notifynum]; }
Call
-(void) Addnotificationaftertime
{
[nsthread Sleepfortimeinterval:20]; How many seconds to hibernate
[ span class= "s2" style= "line-height:1.5;" >self performselectoronmainthread: @selector (addnotifications:) withobject:[nsarray Arraywithobjects:@ "1" ,@ "2" nil] waituntildone:no
[nsthread sleepfortimeinterval:1.0];
}
This is in fact the iphone's universal form of @selector object transfer.
Reprint Please specify: http://www.cnblogs.com/langtianya/p/4199409.html
How the iOS development @selector function passes parameters/How to pass multiple parameters