@dgelessus you're right. sorry! Next time, I'll copy the code!
I changed my code based on your answer: I created a third pyui file for the root view and pushed the root view via code to the navigation view rather than in the UI Builder and I set the button_right_items in the code that loads the root view.
Here's exactly what I did in case someone is stuck with the same very basic problem:
I created a script file with a UI file. They share the same filename (say NavView.py and NavView.pyui). In The pyui file, all I did was set the Custom Class View to ui.NavView. In its corresponding py-file, i created class NavView(ui.View). Also, I created two stand alone UI files for designing the root view and the sub view.
This is the class:
# coding: utf-8
# Load the default view that's placed inside the Navigation View.
# This root view has its own pyui file (here: RootView.pyui).
# That makes it easier to design the root view.
root = ui.load_view('RootView.pyui')
# Set the titlebar text of the Navigation View when the root view is loaded
root.name = 'Root View'
# Specify the visible buttons in the navigation view titlebar when the root view is visible.
root.right_button_items = [ui.ButtonItem(action=self.openSubView, image=ui.Image.named('ionicons-close-24'))]
# Create the Navigation View with the root view preloaded
self.v = ui.NavigationView(root)
# Load the sub view thats loaded when the defined button in the Navigation View is pressed while the root view is loaded
sub = ui.load_view('SubView.pyui')
# This text will be displayed as the Navigation View's titlebar text
sub.name = 'Sub View'
# Display the sub view instead of the root view
# Call the class
If you have any suggestion on how to improve the code, I'd love to hear it!
The above code works great as long as I don't actually want to do anything with the code. I'm not getting it. Did I miss any kind of tutorial or documentation?
Say I have a button in one of the sub views. How do I make the button (with action set to buttonFunction) do anything? def buttonFunction(sender) below the class doesn't work. def buttonFunction(self, sender) inside the class doesn't work either. And it doesn't matter wether every view (not just the Navigation View Container pyui) or just the top level pyui that has the Navigation View in it has its custom view class set to ui.NavView or not.
I'm really confused since I can't find anything like a introduction to Pythonista UI Designer...