ios - Getting all subviews of a subview -



ios - Getting all subviews of a subview -

well, problem can see in image have subview , in subview have other views , within have uilabel , uibuttons.

my question how acess uibuttons , uilabel on each subview in viewdidload can alter aspects of them when app begins.

in test tried alter color of buttons.

i tried using code didn't work:

for (uiview *view1 in self.view.subviews) { nslog(@"%@----", view1); for(uiview *view2 in view1.subviews){ nslog(@"%@", view2); if ([view2 iskindofclass:[uibutton class]]) { [(uibutton *)view2 setbackgroundcolor:[uicolor redcolor]]; } } }

the nslog gives this:

thanks help.

you can either create iboutlets, or utilize unique tags in objects wish refference , utilize viewwithtag reference obejcts pointer.

if utilize viewwithtag, create sure check object pointer against nil, avoid runtime crashes.

to utilize viewwithtag, need assign unique tag in ib, see screenshot:

as see uilabel has here tag of 253 , access it's pointer object have utilize viewwithtag:

uilabel mytaglabel = (uilabel)[self.view viewwithtag:253];

and suggested before using pointer, check against nil:

if (mytaglabel) { //object pointer retrieved mytaglabel.text = @"hello"; }

ios objective-c uiview uiviewcontroller uibutton

Comments

Popular posts from this blog

Delphi change the assembly code of a running process -

json - Hibernate and Jackson (java.lang.IllegalStateException: Cannot call sendError() after the response has been committed) -

C++ 11 "class" keyword -