ios - Naming selector with string -



ios - Naming selector with string -

this question has reply here:

how selector name? 2 answers

i have made button programatically , i'm adding action button this:

[button1 addtarget:self action:@selector(button1) forcontrolevents:uicontroleventtouchupinside];

but want name selector string format.. have tried this:

[b4 addtarget:self action:@selector([nsstring stringwithformat@"button%i", i]) forcontrolevents:uicontroleventtouchupinside];

of course of study doesn't work, there similar can create work? if understand problem..

this work:

nsstring *selname = [nsstring stringwithformat@"button%i", i]; sel selector = nsselectorfromstring(selname); [button1 addtarget:self action:selector forcontrolevents:uicontroleventtouchupinside];

but must inquire why wish this. trying handle several buttons? can done single selector buttons. give each button own tag. button selector can check sender's tag.

ios objective-c

Comments

Popular posts from this blog

web services - java.lang.NoClassDefFoundError: Could not initialize class net.sf.cglib.proxy.Enhancer -

Accessing MATLAB's unicode strings from C -

javascript - mongodb won't find my schema method in nested container -