Last Updated: May 11, 2020
·
2.747K
· stevennunez

RubyMotion and Delegation

Use Interface Builder to delegate actions to fields that accept Delegation. For instance, if you're trying to setup a field to resign being the first responder in a controller:

class SomeController < UIViewController 
  def textFieldShouldReturn(textField)
    titleField.resignFirstResponder
    true
   end 
end

First CTRL drag the text field to the View controller and select delegate. Now you can respond to all delegate-able calls sent to that button.

Alternately you can set the field's delegate to 'self' from the controller to accomplish the same thing in the controller's #viewDidLoad action

class SomeController < UIViewController
  def viewDidLoad
    textField.delegate = self
  end
end