Class: UIAlertView
Class Method Summary collapse
-
.alert(title, options = {}, more_options = {}, &block) ⇒ Object
UIAlertView.alert("title", message: "help!", # The first button is considered the 'cancel' button, for the purposes of # whether the cancel or success handler gets called buttons: %w"Cancel OK No-way", cancel: proc{ puts "nevermind" }, success: proc{ |pressed| puts "pressed: #pressed" }, ).
Instance Method Summary collapse
Class Method Details
.alert(title, options = {}, more_options = {}, &block) ⇒ Object
UIAlertView.alert("title", message: "help!", # The first button is considered the 'cancel' button, for the purposes of # whether the cancel or success handler gets called buttons: %w"Cancel OK No-way", cancel: proc{ puts "nevermind" }, success: proc{ |pressed| puts "pressed: #pressed" }, )
If you choose
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 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/sugarcube-factories/uialertview.rb', line 13 def self.alert(title, ={}, ={}, &block) if .is_a? String [:message] = = end # create the delegate delegate = SugarCube::AlertViewDelegate.new delegate.on_success = [:success] delegate.on_cancel = [:cancel] delegate.on_default = block delegate.send(:retain) args = [title] # initWithTitle: args << [:message] # message: args << delegate # delegate: = [:buttons] || [] if .empty? # cancelButtonTitle: is first, so check for cancel if [:cancel] << "Cancel" end # otherButtonTitles: if .empty? args << nil # cancel button => nil << "OK" # other buttons => "OK" elsif [:success] << "OK" end elsif .length == 1 && [: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 { |m| m && m.localized }) args << nil # otherButtonTitles:..., nil alert = self.alloc alert.send(:"initWithTitle:message:delegate:cancelButtonTitle:otherButtonTitles:", *args) if .key?(:style) style = [:style] style = style.uialertstyle if style.respond_to?(:uialertstyle) alert.alertViewStyle = style end if .fetch(:show, true) alert.show end alert end |
Instance Method Details
#<<(title) ⇒ Object
68 69 70 |
# File 'lib/sugarcube-factories/uialertview.rb', line 68 def <<(title) addButtonWithTitle(title) end |