In my iPad application I have an UIView
with multiple subviews, each one with a different tag value.
I want to search for a subview with specific tag value. Currently I am using the for() loop for looping through to find a specific UIView
with the required tag.
for (int i=0; i<[[myView subviews] count]; i++) {
if ([[[myView subviews] objectAtIndex:1] tag]==1) {
//assign that view
}
}
I just want to know, whether [myView viewWithTag:1]
also use same way to find that specific tagged view and which way is faster
Not exactly the same, viewWithTag
uses depth-first search to find the subview. In another word, it scans all subviews recursively until it finds an UIView
with a tag equals to the parameter.
See also in Apple official Documentation