Last active
December 11, 2015 20:48
-
-
Save jinqian/4657702 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Example of delegation in RubyMotion | |
class MsActivityView < UIView | |
attr_accessor :delegate | |
def initWithFrame(frame) | |
super | |
#... | |
@cancelButton = UIButton.alloc.init | |
@cancelButton.addTarget( | |
self, | |
action: :cancel, | |
forControlEvents:UIControlEventTouchUpInside | |
) | |
end | |
def cancel | |
self.delegate.public_send(:activityViewDidCancel, self) | |
end | |
end | |
class MsScannerViewController < UIViewController | |
# ... | |
def setActivityView(show) | |
activityIndicator = MsActivityView.alloc.initWithFrame(frame) | |
activityIndicator.text = "Searching" | |
activityIndicator.isAnimating = true | |
# Define delegation | |
activityIndicator.delegate = self | |
# Place activity view at the navigation controller level to make sure it ignores tap gestures | |
self.navigationController.view.addSubview(activityIndicator) | |
end | |
def activityViewDidCancel(view) | |
self.scannerSession.cancel | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment