Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Dynamic View Name error
-
I'm trying to use the page name as a sort of dynamic label, sending information to the user in a convenient way. I can get this to work using just the custom view but it doesn't seem to work when the view is being presented via the navigation view.
Here's the code I'm testing with, any help would be appreciated:
import ui class CustomView (ui.View): def __init__(self): ui.View.__init__(self, name = 'Test') def touch_began(self, touch): self.name = str(touch.location) def touch_moved(self, touch): self.name = str(touch.location) def touch_ended(self, touch): self.name = 'Test' view = CustomView() nav = ui.NavigationView(view) view.left_button_items = [ui.ButtonItem(image = ui.Image.named('ionicons-close-24'), action = lambda sender: nav.close())] nav.present(hide_title_bar = True)
-
I found no useful clues...
ui.did_load()
is only called afterui.load_view()
so it will not be called in your script.I did find a way to crash Pythonista but nothing of value.
import ui view = ui.Label(name='hi') nav = ui.NavigationView(view) nav.present() nav.push_view(view)
-
I didn't realize that initially. I guess I just forgot to take it out after I figured it out.
-
@ omega() It looks like the name of the View used for the navigation bar is taken from the View at time of instantiation and not updated dynamically or exposed as an attribute that you could update. I don't know if you are willing to show the title bar, if so, you can change the NavigationView's name from your functions...
import ui class CustomView (ui.View): def __init__(self): ui.View.__init__(self, name = 'Test') def touch_began(self, touch): self.name = str(touch.location) def touch_moved(self, touch): self.name = str(touch.location) ### self.navigation_view.name = str(touch.location) ### def touch_ended(self, touch): self.name = 'Test' view = CustomView() nav = ui.NavigationView(view) view.left_button_items = [ui.ButtonItem(image = ui.Image.named('ionicons-close-24'), action = lambda sender: nav.close())] nav.present() #hide_title_bar = True)
Edit: to remove global
-
I would prefer to keep the title bar hidden (it just looks better that way), but I will use navigation view's name as a temporary solution. I was hoping for something that would force the navigation view to ask for the view's name again but I haven't seen anything like that in the documentation. Maybe this is just a bug?
-
@Omega() By the way... cool button one liner! I like it.