iphone - iterating through subviews - how to reach to all UI objects -
i have created xib file custom uiview
, loaded xib custom uiview
with;
nsarray *views = [[nsbundle mainbundle] loadnibnamed:@"productdetailview" owner:self options:nil]; self = [views objectatindex:0];
i didn't wanted define subviews iboutlets, instead thought iterating through subviews more appropriate.
(id subview in self.subviews) { if ([subview iskindofclass:[uiview class]]) { uiview *theview = (uiview*)subview; if (theview.tag == 16) { // tag 16 specific uiviews... stuff } } else if ([subview iskindofclass:[uilabel class]]) { uilabel *thelabel = (uilabel*)subview; if (thelabel.tag == 21) { // tag 17 specific uilabels... stuff } else { // no tag... stuff } } }
i thought more robust, since uilabel
s inherited uiview
s, cannot utilize approach. aware changing if orders can create work, not feeling depend on order if-clauses
what asking is, logical approach in such situation? should using viewwithtag:
function instead of looping through id
s , casting?
if want test specific type of object utilize ismemberofclass
rather iskindofclass
, tests if object of specified class or inherits specified class.
iphone ios objective-c cocoa-touch
No comments:
Post a Comment