Class: SugarCube::ActionSheetDelegate

Inherits:
Object
  • Object
show all
Defined in:
lib/ios/sugarcube-factories/uiactionsheet.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#buttonsObject

Returns the value of attribute buttons.



154
155
156
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 154

def buttons
  @buttons
end

#on_cancelObject

Returns the value of attribute on_cancel.



156
157
158
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 156

def on_cancel
  @on_cancel
end

#on_defaultObject

Returns the value of attribute on_default.



155
156
157
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 155

def on_default
  @on_default
end

#on_destructiveObject

Returns the value of attribute on_destructive.



157
158
159
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 157

def on_destructive
  @on_destructive
end

#on_successObject

Returns the value of attribute on_success.



158
159
160
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 158

def on_success
  @on_success
end

Instance Method Details

#actionSheet(alert, didDismissWithButtonIndex: index) ⇒ Object



160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# File 'lib/ios/sugarcube-factories/uiactionsheet.rb', line 160

def actionSheet(alert, didDismissWithButtonIndex: index)
  handler = nil
  if index == alert.destructiveButtonIndex && on_destructive
    handler = on_destructive
  elsif index == alert.cancelButtonIndex && on_cancel
    handler = on_cancel
  elsif index != alert.destructiveButtonIndex && index != alert.cancelButtonIndex && on_success
    handler = on_success
  end
  handler ||= on_default

  if handler
    if handler.arity == 0
      handler.call
    else
      button = buttons[index]

      if handler.arity == 1
        handler.call(button)
      else
        handler.call(button, index)
      end
    end
  end

  self.send(:autorelease)
end