0

I have a UIScrollView with a custom view called LVSBBView. LVSBBView has subviews that are of custom type LVSBBNode. These nodes are created recursively (like a tree) and I'd like to be able to create a new "child" node within LVSBBNode and then make it a subview of LVSBBView. This doesn't seem to be working -- the new views never show up. If I create all the views within LVSBBView's controller, it works OK.

The code I'm using to create the "child" node within LVSBBNode is:

LVSBBNode *child = [[LVSBBNode alloc] init];
// ...set properties of child here...
[self.superview addSubview:child];

Suggestions?

LarrySnyder610
  • 2,277
  • 12
  • 24
  • 3
    Seems like it should work. Is `self.superview` `nil` when you call `addSubview:`? Are you also sure that the new child node is placed properly visually? – Aaron Jul 16 '14 at 18:06
  • You can also split out the `recursiveDescription` on any `UIView` to the log, this will tell you if in-fact your child node is being added to the view hierarchy : http://stackoverflow.com/questions/2343246/i-need-to-inspect-the-view-hierarchy-on-an-iphone-program – Aaron Jul 16 '14 at 18:09
  • @Aaron: Turns out `self.superview` **was** `nil`. I was creating the child nodes before adding the root node as a subview. Oops! Thanks for the suggestion. (Also, `recursiveDescription` is a nice trick -- thanks for that too.) – LarrySnyder610 Jul 16 '14 at 19:04
  • Sure, I'll re-add all that as an answer. – Aaron Jul 16 '14 at 19:12

1 Answers1

1

Seems like it should work. I bet self.superview is nil when you call -addSubview:

You can also split out the -recursiveDescription on any UIView to the log. This will tell you if in-fact your child node is being added to the view hierarchy: I need to inspect the view hierarchy on an iPhone program

Community
  • 1
  • 1
Aaron
  • 7,055
  • 2
  • 38
  • 53