Search code examples
iosdelegatesrubymotion

RubyMotion: Find each character entry in UITextField


I am new to RubyMotion for iOS app, but I coded using Objective C.

My requirement is to get the delegate method which should be called for every char type in UITextField.

Objective C: I used "shouldChangeCharactersInRange" for finding the user character entry.

Can you anyone suggest me how to implement this function in RubyMotion for tracking character type in UITextField

Thank you.

Regards.


Solution

  • First, when you create the text field, make sure you set the delegate to the same View Controller class it's in:

    textField = UITextField.alloc.initWithFrame([[10,200],[300,40]])
    textField.delegate = self
    

    Then add this method to that class:

    def textField(textField, shouldChangeCharactersInRange:range, replacementString:string)
      # return true or false based on whether you want to allow the replacement
      true
    end