How can I iterate thru all controls from a View on iOS?
I want to iterate thru all controls existing in a View on iOS when the view is loaded.
Also, it would be acceptable to have a callback that is called when these contr开发者_运维技巧ols are initialized.
How can I obtain this?
To iterate through subviews (controls) in a parent view, call the parent view's -subviews
method:
for (UIView *subview in [parentView subviews]) {
/* do something with subview */
}
You could subclass the control, creating a custom control. Here, you override the custom control view's initializer method. In this method, you would call the parent's initializer, and add your custom code.
for (UIView *aView in [myView subviews]) { //do something with aView }
?
精彩评论