0

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.

junet
  • 57
  • 10
  • from viewdidload if u try doing this it will not work. Try implementing the same in Viewwillappear. This is happening because only viewcontoller will be loaded in viewdidload. All the subviews will be loading after that. – Ashwin P Sep 01 '15 at 15:28
  • Is your the view you created in de xib-file properly linked to your code property? – Maarten Sep 01 '15 at 15:32

1 Answers1

0

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].

See also my answer to an old question that might help you.

Community
  • 1
  • 1
DarkDust
  • 90,870
  • 19
  • 190
  • 224