Class: UIAlertView
- Inherits:
-
Object
- Object
- UIAlertView
- Defined in:
- lib/sugarcube/uialertview.rb
Class Method Summary collapse
-
.alert(title, options = {}, &block) ⇒ Object
UIAlertView.alert(“title”, message: “help!”, buttons: %w“OK Cancel No-way”, cancel: proc{ puts “nevermind” }, success: proc{ |pressed| puts “pressed: #pressed” }, ).
Class Method Details
.alert(title, options = {}, &block) ⇒ Object
UIAlertView.alert(“title”,
message: "help!",
buttons: %w"OK Cancel No-way",
cancel: proc{ puts "nevermind" },
success: proc{ |pressed| puts "pressed: #{pressed}" },
)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/sugarcube/uialertview.rb', line 9 def self.alert(title, ={}, &block) puts puts block # create the delegate delegate = SugarCube::AlertViewDelegate.new delegate.on_success = block || [:success] delegate.on_cancel = [:cancel] delegate.send(:retain) args = [title] # initWithTitle: args << [:message] # message: args << delegate # delegate: = [:buttons] || [] if .empty? # cancelButtonTitle: is first, so check for cancel << "Cancel" if [:cancel] # otherButtonTitles: << "OK" if [:success] or .empty? elsif .length == 1 and [:cancel] raise "If you only have one button, use a :success handler, not :cancel (and definitely not BOTH)" end # the button titles. These are passed to the success handler. delegate. = # uses localized buttons in the actual alert args.concat(.map{ |s| s.localized }) args << nil # otherButtonTitles:..., nil alert = self.alloc alert.send(:"initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:", *args) alert.show alert end |