The @selector function of iOS passes multiple parameters

Source: Internet
Author: User

1. General situation, use self performselector:sel Withobject:id method

[Self Performselectoronmainthread: @selector (testaa:) withobject:[nsarray arraywithobjects:@ "1" @ "2", nil] waituntildone:no];-(void) Testaa: (nsarray*) data{     if (data==nil| | data.count!=2) {        return;    }    Nsinteger num=[(nsstring*) data[0] intvalue];    Nsinteger index=[data[1] intvalue];}

2, Nstimer: The object that passes the parameter is stored in the Nstimer userinfo dictionary.

Nsmutabledictionary *dict = [[Nsmutabledictionary alloc] init];  [Dict setobject:oldview forkey:@ "Oldview"]; [Nstimer scheduledtimerwithtimeinterval:0.0 target:self selector: @selector (onTimer:) userinfo:dict Repeats:no];  [Dict release];-(void) OnTimer: (Nstimer *) Timer {      UIView *oldview = [[Timer userInfo] objectforkey:@ "Oldview"];}

3, UIButton class: By setting tag to use

UIButton * Markbutton=[[uibutton alloc] Initwithframe:cgrectmake (280, 0, 30, 30)]; [email protected] "parameter value"; Here is the parameter value you want to pass [Markbutton addtarget:self action: @selector (Addmark:)  forcontrolevents: uicontroleventtouchupinside];-(BOOL) Addmark: (UIButton *) btn {    NSLog (@ "%@", Btn.tag];}

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

The @selector function of iOS passes multiple parameters

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.