Search code examples
iossubviewsuperview

iOS: Can a view place another subview on its superview?


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?


Solution

  • 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