Forum Archive

Textfields delegator does not work

sendog3c

Hello community:

Here I am again looking for help about a textfields delegators. I have used the example of delegator found here but does not work to me. Would you please help explain me how it is works. Thanks.

import ui
import console

textfield1 = ui.TextField()
textfield2 = ui.TextField()
textview1 = ui.TextView()
label1= ui.Label()

class MyTextFieldDelegate (object):
    def textfield_should_begin_editing(self, textfield):
        alert_result = console.alert("textfield_should_begin_editing")

    def textfield_did_begin_editing(self, textfield):
            alert_result = console.alert("textfield_did_begin_editing")

    def textfield_did_end_editing(self, textfield):
            alert_result = console.alert("textfield_did_end_editing")

    def textfield_should_return(self, textfield):
            alert_result = console.alert("textfield_should_return")

    def textfield_should_change(self, textfield, range, replacement):
        alert_result = console.alert("textfield_should_change")

    def textfield_did_change(self, textfield):
        alert_result = console.alert("textfield_did_change")



def button_tapped(sender):

    button_definition = sender.title

    if button_definition == "SUM":

        label1 = sender.superview['label1'].text = "+"

        textfield1 = MyTextFieldDelegate()

        #sender.superview['textfield1'] = MyTextFieldDelegate()

    if button_definition == "SUBS":
        #alert_result = console.alert(button_definition)
        label2 = sender.superview['label1'].text = "-"

    if button_definition == "MULT":
        #alert_result = console.alert(button_definition)
        label3 = sender.superview['label1'].text = "*"  

    if button_definition == "DIV":
        #alert_result = console.alert(button_definition)
        label4 = sender.superview['label1'].text = "/"  

def funcion_suma(sender, button_definition):
        pass

def funcion_multi(sender, button_definition):
        pass

def funcion_division(sender, button_definition):
        pass

ui.load_view('MATHFUN').present('sheet')
mikael

@sendog3c said:

textfield1 = MyTextFieldDelegate()

You need to set your delegate as a delegate.

textfield1.delegate = MyTextFieldDelegate()
sendog3c

Hi Mikael:

It is non working still 🥺

cvp

@sendog3c problem of sequence 😀

v = ui.load_view('MATHFUN')
v['textfield1'].delegate = MyTextFieldDelegate()
v.present('sheet')