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.
How would I implement a delegate?
-
From what I understand, a delegate is a function that gets called whenever it's action occurs. I have my function, but it's not being called. Here's what I have:
class myclass(): ig=ui.load_view('myview') tv=ig['textview1'] def textview_did_change(self, textview): print'hi'
How would I properly implement my delegate?
-
@Brian, delegate is not a function, but a class.<br>
Check this:import ui, console class Delegate: def textview_did_change(self, textview): console.hud_alert("textview_did_change!") view = ui.View() textview = ui.TextView() textview.delegate = Delegate() # This is the line you are looking for textview.flex = "WH" view.add_subview(textview) view.present("fullscreen")
-
@ShadowSlayer
Could you provide an example of how to do this while using ui.load_view()?
I can't seem to get it working. -
In your example, you would use
tv.delegate=Delegate()
Where you implemented Shadow's Delegate class example.
-
@Brian, read the docs :)<br>
When you useui.load_view()
, it returns aui.View
object. In the UI editor you can select your textview element and set it's name to something like "mytextview". Then you can usetextview = view["mytextview"]
.<br>
Check this:import ui ... view = ui.load_view("uifile") textview = view["mytextview"] textview.delegate = Delegate() ...
-
When I append text to the text box, the delegate is not called even when I have it properly configured. Is this intentional or is it a bug? Also thanks for the help, much was learned.
-
@Brian, do you mean my example? If you are talking about your code, could you please post it so I can take a look and maybe find out the problem?