Sub views of NavigationView are not accessiblebrowsing

Using the UI editor I have created an instance of a "NavigationView" with several "Buttons" as subviews to push the child views. So far I had handled the control of the sub views individually, meaning I explicitly hardcoded the calls to push_view. Now I tried to this generically by accessing the button views using the "[]" operator and the buttons' names. However, none of the buttons could be found by name. Using the "subviews()" method I tried to iterate over the subviews only to find that the NavigationView does not seem to have a single sub view. Is this intended? Are NavigationViews treated in a special way when it comes to view hierarchy? Or is this a bug?

I'm also unsure how to use the NavigationView in this way. I've placed a tableview within the nav and I'm unsure how to access this root view in code to set the delegate and data source so that I can push selected table rows onto the stack. I know that I can call push and pop once I have an initial selection, however.

Can you post your pyui so we can understand what you are trying to do?

Or a little more explanation of how you created your view. Why are you trying to access the button's using [] rather than using sender? Are the buttons in "pushed" views, or truly subviews of the NV. Or as left_buttons / right_buttons in the title bar?

The pushed views of a NV are not subviews, yes it is strange.

If you want to see where your buttons live, you could use print sender.superview, and so on up the superview chain until you get to the top view.

I'm afraid I have to ask a very stupid question: How do I access the pyui files? There's an export feature for the py the files but I haven't found one for the pyui files. To me they are still black boxess still. Thanks!

When starting from a new pyui file, if you add a navigation view and then add views within the nav view using the UI designer, those views do not appear as .subviews. Where are they? I think that this is essentially an attempt at creating a root view of the nav controller. Also an issue with this approach is that any subsequent views pushed to the stack will underlay the buttons and touch event on the pushed view will not work.

One solution could be to instead programmatically push another pyui file with your buttons onto the nav stack. However, this results in odd behavior because the view pushed will seem to be the second view on the stack. I.e. You will be able to navigate backwards to an empty view from the button view.

yes it does appear that the "subview" of a navigationview in the ui editor sets the root view. But since you cannot easily access the rootview of a navigationview after it is created this leads to some awkward situations.

Here is a way to get the rootview of a nav view, which only relies on a small bit of gc magic:

def get_navigationview_root(nv):
o=[v for v in gc.get_objects() if hasattr(v,'navigation_view') and v.navigation_view==nv and not v.superview]
return o[0]

@JonB After the issue of NavigationViews has been dormant for a while I picked it up again and tried your little helper function. Unfortunately, it did not work for me since the object set always seems to be empty for navigation views.

turns out you must present the view before this trick works. here I created a view in the ui editor, added a navigationview, then added a subview to the navigation view, to which i added a button. after loading then presenting, you can find the view which the nav view is showing. (this works for finding the active view of a navigation view, since other views will not have the navigation_view attribute pointing at the nav view object). If you gave the view a unique viewname, you could filter by name and that should work before the nv is presented. It would also be possible to store a list of views from gc before and after loading the view, and then filtering by name, or views with no superviews, etc. just make sure you delete the list so you don't hang onto references to discarded objects.