uiview - Adding actions to buttons in a subview -


in app call uiview , uiview settings screen in app , have buttons in uiview , question how add actions buttons iv added uiviews subview? thanks,

assuming you're writing code in view controller settings uiview, uiview bound view property of controller, , have referenced 1 of buttons variable button, here write:

- (void)viewdidload {     [super viewdidload];     [button addtarget:self                action:@selector(buttonpressed)      forcontrolevents:uicontroleventtouchupinside]; }  - (void)buttonpressed {     // things here in response button being pressed } 

another way write method passing in pointer button pressed, so:

- (void)viewdidload {     [super viewdidload];     [button addtarget:self                action:@selector(buttonpressed:) // note colon here      forcontrolevents:uicontroleventtouchupinside]; }  - (void)buttonpressed:(id)sender {     uibutton *buttonwhichwaspressed = (uibutton *)sender;     // can things hide button, change text, etc. } 

rather calling addtarget:action:forcontrolevents:, though, in interface builder (you should doing this) after defining buttonpressed or buttonpressed: method above, in .xib file button go second tab in inspector after clicking on button (it should button connections), , click-drag touch inside event file's owner, , select "buttonpressed" list.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

visual c++ - Using relative values in array sorting ( asm ) -