class UITextField
Methods which use blocks for UITextFieldDelegate methods. EX field.should_end? do |text_field|
if text_field.text != "secret" return false end true
end
Also includes an on_change
method, which calls after the text has changed (there is no UITextFieldDelegate equivalent.) EX field.on_change do |text_field|
p text_field.text
end
Public Instance Methods
on_begin(&block)
click to toggle source
block takes argument textField
# File lib/formotion/patch/ui_text_field.rb, line 26 def on_begin(&block) add_delegate_method do @delegate.textFieldDidBeginEditing_callback = block end end
on_change(&block)
click to toggle source
block takes argument textField
# File lib/formotion/patch/ui_text_field.rb, line 54 def on_change(&block) add_delegate_method do @delegate.on_change_callback = block self.addTarget(@delegate, action: 'on_change:', forControlEvents: UIControlEventEditingChanged) end end
on_end(&block)
click to toggle source
block takes argument textField
# File lib/formotion/patch/ui_text_field.rb, line 40 def on_end(&block) add_delegate_method do @delegate.textFieldDidEndEditing_callback = block end end
should_begin?(&block)
click to toggle source
block takes argument textField; should return true/false
# File lib/formotion/patch/ui_text_field.rb, line 19 def should_begin?(&block) add_delegate_method do @delegate.textFieldShouldBeginEditing_callback = block end end
should_change?(&block)
click to toggle source
block takes argument textField, range [NSRange], and string; should return true/false
# File lib/formotion/patch/ui_text_field.rb, line 47 def should_change?(&block) add_delegate_method do @delegate.shouldChangeCharactersInRange_callback = block end end
should_clear?(&block)
click to toggle source
block takes argument textField; should return true/false
# File lib/formotion/patch/ui_text_field.rb, line 62 def should_clear?(&block) add_delegate_method do @delegate.textFieldShouldClear_callback = block end end
should_end?(&block)
click to toggle source
block takes argument textField; should return true/false
# File lib/formotion/patch/ui_text_field.rb, line 33 def should_end?(&block) add_delegate_method do @delegate.textFieldShouldEndEditing_callback = block end end
should_return?(&block)
click to toggle source
block takes argument textField; should return true/false
# File lib/formotion/patch/ui_text_field.rb, line 69 def should_return?(&block) add_delegate_method do @delegate.textFieldShouldReturn_callback = block end end
Private Instance Methods
add_delegate_method() { || ... }
click to toggle source
# File lib/formotion/patch/ui_text_field.rb, line 76 def add_delegate_method # create strong reference to the delegate # (.delegate= only creates a weak reference) @delegate ||= UITextField_Delegate.new yield self.delegate = @delegate end