Class: SugarCube::AlertViewDelegate
- Defined in:
- lib/ios/sugarcube-factories/uialertview.rb
Instance Attribute Summary collapse
-
#buttons ⇒ Object
Returns the value of attribute buttons.
-
#on_cancel ⇒ Object
Returns the value of attribute on_cancel.
-
#on_default ⇒ Object
Returns the value of attribute on_default.
-
#on_success ⇒ Object
Returns the value of attribute on_success.
Instance Method Summary collapse
Instance Attribute Details
#buttons ⇒ Object
Returns the value of attribute buttons.
109 110 111 |
# File 'lib/ios/sugarcube-factories/uialertview.rb', line 109 def @buttons end |
#on_cancel ⇒ Object
Returns the value of attribute on_cancel.
110 111 112 |
# File 'lib/ios/sugarcube-factories/uialertview.rb', line 110 def on_cancel @on_cancel end |
#on_default ⇒ Object
Returns the value of attribute on_default.
112 113 114 |
# File 'lib/ios/sugarcube-factories/uialertview.rb', line 112 def on_default @on_default end |
#on_success ⇒ Object
Returns the value of attribute on_success.
111 112 113 |
# File 'lib/ios/sugarcube-factories/uialertview.rb', line 111 def on_success @on_success end |
Instance Method Details
#alertView(alert, didDismissWithButtonIndex: index) ⇒ Object
114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 |
# File 'lib/ios/sugarcube-factories/uialertview.rb', line 114 def alertView(alert, didDismissWithButtonIndex:index) handler = nil if index == alert.cancelButtonIndex handler = on_cancel else handler = on_success end handler ||= on_default args = nil if handler if handler.arity == 0 args = [] else # construct all the possible arguments you could send args = [[index]] # add the first input if this is not the default if alert.alertViewStyle != UIAlertViewStyleDefault args << alert.textFieldAtIndex(0).text end # add the second one if this is a login+password input if alert.alertViewStyle == UIAlertViewStyleLoginAndPasswordInput args << alert.textFieldAtIndex(1).text end # and maybe you want the index, too args << index # but only send the ones they asked for args = args[0...handler.arity] end handler.call(*args) end self.send(:autorelease) end |