Below is a better example of using a delegate, I think. But it also shows how flexible the delegates are. The fact that you can point the delegate to your own class is very nice. Most of the lines are setting up the view. To make a real,example you need it. But 95% of the lines in the example are just a pattern so to speak.
This is just another way. Not saying it's the best way.
```python
Pythonista Forum - @Phuket2
import ui
class MyClass(ui.View):
def init(self, args, kwargs):
super().init(args, **kwargs)
self.make_view()
self.value = None
def make_view(self):
tf = ui.TextField(frame = self.bounds.inset(10, 10))
tf.height =32
tf.delegate = self
tf.flex = 'w'
self.add_subview(tf)
# because the delegate is pointed to this class, tf.delegate=self,
# then you can define the delegate methods here. in the docs it
# explains you only need to define the methods you need. the meaning
# being is that the the caller is checking to see if the method
# exists before calling it.
def textfield_did_change(self, textfield):
self.value = textfield.text
if name == 'main':
w, h = 600, 800
f = (0, 0, w, h)
style = 'sheet'
mc = MyClass(frame=f, bg_color='white')
mc.present(style=style, animated=False)
mc.wait_modal()
print(mc.value)
```