6n3isq
Last Updated: February 20, 2016
·
2.29K
· stevennunez
148187 557681800912781 556845050 n

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
Say Thanks
Respond