I have two views, one is created from interface builder, and the other is programmatically created.
What I want to do is to bring programmatically-created view to forward. But xib-created view is always displayed on the first. In viewDidLoad, I'm using sendSubviewToBack:
to do this, but it seems this code doesn't work.
Some might say that I should create these views only by xib (or only by code). But I don't want to do so.
Is there a good solution to achieve this?
Your thoughts and help will be hugely appreciated.
Most likely your problem is that you calling sendSubviewToBack:
with a view that is not a direct subview of the receiver.
The sendSubviewToBack:
/ bringSubviewToFront:
methods work for direct subviews of a view. So if you a view hierarchy like this:
A
\
B - D
|
C - E
(B and C are both subviews of A; B has a subview D, C has a subview E)
then you can do [A sendSubviewToBack:C]
, but you cannot do [A sendSubviewToBack:E]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.