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

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

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