Last active
December 14, 2015 23:08
-
-
Save ddrscott/5163136 to your computer and use it in GitHub Desktop.
RubyMotion UIBarButtonItem Helper
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: | |
# self.navigationItem.leftBarButtonItems = [ | |
# ui_bar_button_item('1'){App.alert('One')}, | |
# ui_bar_button_item('2'){App.alert('Two')} | |
# ] | |
def ui_bar_button_item(title, &block) | |
item = UIBarButtonItem.alloc.initWithTitle(title, style: UIBarButtonItemStylePlain, target: block, action: :call) | |
item.instance_variable_set('@_target', block) # retain | |
item | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Line #8
instance_variable_set
is critical because the block doesn't seem to be retained in UIBarButtonItem.I'm not sure if this will create memory leaks or not :/