HI, I have Parentview-->Multiple childviews. when i use [self bringSubviewToFront:childview] in parentview, it works fine.but after adding grandchildview to childview,when i use [self bringSubviewToFront: grandchildview] in parentview, it did not work?any help please?
+1
A:
The -[UIView bringSubviewToFront:]
method only works for direct children, not grandchildren. Remember that the view hierarchy is tree, and normally a view only knows about its "parent" (or superview) and its direct "children" (or subviews). You would need to do something like this (untested):
// First, get the view embedding the grandchildview to front.
[self bringSubviewToFront:[grandchildview superview]];
// Now, inside that container view, get the "grandchildview" to front.
[[grandchildview superview] bringSubviewToFront:grandchildview];
DarkDust
2010-09-22 06:39:34
work fine ...great code!
Mikhail Naimy
2010-09-22 07:42:47