Skip to content

Instantly share code, notes, and snippets.

@mjmsmith
Created May 8, 2012 22:09
Show Gist options
  • Save mjmsmith/2639802 to your computer and use it in GitHub Desktop.
Save mjmsmith/2639802 to your computer and use it in GitHub Desktop.
playing with RubyMotion
class BlockAlert
def initWithTitle(title, message:message)
@alert = UIAlertView.alloc.initWithTitle(title, message:message, delegate:self, cancelButtonTitle:nil, otherButtonTitles:nil)
@blocks = []
self
end
def show
@alert.show()
end
def dismissAnimated(animated)
@alert.dismissWithClickedButtonIndex(-1, animated:animated)
end
def addButtonWithTitle(title, block:block)
block = lambda {} if !block
@alert.addButtonWithTitle(title)
@blocks << block
end
def alertView(alertView, didDismissWithButtonIndex:buttonIndex)
if buttonIndex >= 0 && buttonIndex < @blocks.size
@blocks[buttonIndex].call()
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment