Skip to content

Instantly share code, notes, and snippets.

@workwithnano
Created November 10, 2012 23:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save workwithnano/4052921 to your computer and use it in GitHub Desktop.
Save workwithnano/4052921 to your computer and use it in GitHub Desktop.
Calling define_method in RubyMotion Module (v 1.27)
module MTFGestures
def gestureRecognizerWithCompletionBlock( gestureClassString, target, completion )
case gestureClassString
when "UIPanGestureRecognizer" then
# Define the panning delegate method based
# on the completion handler passed to this
# function.
define_method "panning" do |sender|
completion( sender )
end
# Create the pan gesture recognizer and
# send it along to our fake delegate method
panGestureRecognizer = UIPanGestureRecognizer.alloc.initWithTarget( target, action:"panning" )
self.view.addGestureRecognizer( panGestureRecognizer )
else
raise "#{gestureClassString} is not a supported gesture yet."
end
end
end
@workwithnano
Copy link
Author

This module is included in another class. It's not used as a static-method Module.

@workwithnano
Copy link
Author

An error occurs when define_method is called:

mtf_gestures.rb:12:in gestureRecognizerWithCompletionBlock:': undefined methoddefine_method' for #MTFDuoViewController:0x9d0a0b0 (NoMethodError)

MTFDuoViewController is the Class which calls "include MTFGestures"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment