iphone - Dynamically declare function name? -


i creating list of bar buttons action functions (sfuncname below), dynamically changed.

when user clicks on button, sfuncname called.

for(int = 0; < 3 ; i++){          nsstring* sfuncname = [nsstring stringwithformat:@"onfunc_%d:", ];         barbuttonitem = [[uibarbuttonitem alloc] initwithbarbuttonsystemitem:systemitem target:self                       action:nsselectorfromstring(sfuncname)]; } 

the question is: have got way dynamically declare sfuncname respond buttons?

example:

for(int = 0; < 3 ; i++){          nsstring* sfuncname = [nsstring stringwithformat:@"onfunc_%d:", ];         - (void)sfuncname: (id)sender; //sfuncname: onfunc_0, onfunc_1, onfunc_2  } 

i don't see advantage of creating method declaration dynamically, code within these methods wouldn't dynamic either.

so should rather declare single method called every button, pass tag or reference sender (button) or other value enables method tell button has been tapped prior method being called. this:

-(void)buttonpressed: (int)tag {     if (tag == 0) {       // code first button    }     if (tag == 1) {       // code second button    }     // prepare code further buttons...  } 

Comments

Popular posts from this blog

c++ - Convert big endian to little endian when reading from a binary file -

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

unicode - Are email addresses allowed to contain non-alphanumeric characters? -