ios - Create a few UIButton programmatically and reconstruct the object later using tag? -


i creating few buttons programmatically, similar to:

for( int = 0; < 5; i++ ) {   uibutton* abutton = [uibutton buttonwithtype:uibuttontyperoundedrect];   [abutton settag:i];   [abutton addtarget:self action:@selector(buttonclicked:) forcontrolevents:uicontroleventtouchupinside];   [aview addsubview:abutton]; } 

and can implement function of button way know witch 1 tapped:

- (void)buttonclicked:(uibutton*)button {   nslog(@"button %ld clicked.", (long int)[button tag]); } 

but question little bit trickier that, don't want access button inside it's button method outside of can change uibutton frame using animation.

i thinking should somehow able recreate pointer of buttons created using tags assign initially. can point me in right direction?

the correct way using next line of code:

uibutton *abuttonreconstruct = (uibutton *)[self.view viewwithtag:atag]; 

where atag int , greater 0, because views have tag 0 default, in loop used in first place, count should start @ minimum 1. in our case atag having values 1 6 after change loop.

also there shouldn't more view same tag.


Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -