Because right now, viewWithTag
actually search for itself first, and then all subviews recursively down the whole subtree, for a view with that tag.
But wha
Take advantage of the recursive nature of -viewWithTag:
- (UIView *)viewWithTagNotCountingSelf:(NSInteger)tag
{
UIView *toReturn = nil;
for (UIView *subView in self.subviews) {
toReturn = [subView viewWithTag:tag];
if (toReturn) {
break;
}
}
return toReturn;
}
Edit: this will drill down farther than "grand-subviews": it will get any view within the hierarchy that is not self. Also this is to be implemented in a category on UIView
.