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
Written by Steven Nunez
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#