infinitered / redpotion

We believe iPhone development should be clean, scalable, and fast with a language that developers not only enjoy, but actively choose. With the advent of Ruby for iPhone development the RubyMotion community has combined and tested the most active and powerful gems into a single package called RedPotion
MIT License
233 stars 40 forks source link

Undefined method make_button #97

Closed andersennl closed 9 years ago

andersennl commented 9 years ago

Hi, In a PM::TableScreen I'm trying to use the app.make_button method to create some buttons for an ActionSheet. Unfortunately I get an undefined method error.

I copied the button code from an example of the docs, my code looks basically like this (the error happens using this code):

class HomeTableScreen < PM::TableScreen
  title "Test"
  stylesheet HomeTableScreenStylesheet

  def on_load
    some_action
  end

  def table_data
    [{ cells: some_data }]
  end

  def some_action
    taco = app.make_button("Taco") {
            puts "Taco pressed"
          }
  end
end

Here is the stack trace (I can provide the generated crashlog if needed):

undefined method `make_button' for RubyMotionQuery::App:Class (NoMethodError)
2015-05-10 12:42:15.041 testapp[7212:7434475] *** Terminating app due to uncaught exception 'NoMethodError', reason: 'home_table_screen.rb:29:in `gram_button': undefined method `make_button' for RubyMotionQuery::App:Class (NoMethodError)
'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010343ec65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010077ebb7 objc_exception_throw + 45
    2   testapp                            0x000000010036a91f _ZL10__vm_raisev + 399
    3   testapp                            0x000000010036aa4d rb_vm_raise + 205
    4   testapp                            0x0000000100268b59 rb_exc_raise + 9
    5   testapp                            0x0000000100368cc2 rb_vm_method_missing + 786
    6   testapp                            0x000000010033bbf5 rb_vm_dispatch + 5925
    7   testapp                            0x000000010033a38d rb_vm_trigger_method_missing + 1053
    8   testapp                            0x000000010033b5ef rb_vm_dispatch + 4383
    9   testapp                            0x00000001000415bc vm_dispatch + 1436
    10  testapp                            0x0000000100226a43 rb_scope__gram_button__ + 355
    11  testapp                            0x0000000100226fcd __unnamed_29 + 13
    12  UIKit                               0x0000000100ca2da2 -[UIApplication sendAction:to:from:forEvent:] + 75
    13  UIKit                               0x0000000100ca2da2 -[UIApplication sendAction:to:from:forEvent:] + 75
    14  UIKit                               0x0000000100db454a -[UIControl _sendActionsForEvents:withEvent:] + 467
    15  UIKit                               0x0000000100db3919 -[UIControl touchesEnded:withEvent:] + 522
    16  UIKit                               0x0000000100cef998 -[UIWindow _sendTouchesForEvent:] + 735
    17  UIKit                               0x0000000100cf02c2 -[UIWindow sendEvent:] + 682
    18  UIKit                               0x0000000100cb6581 -[UIApplication sendEvent:] + 246
    19  UIKit                               0x0000000100cc3d1c _UIApplicationHandleEventFromQueueEvent + 18265
    20  UIKit                               0x0000000100c9e5dc _UIApplicationHandleEventQueue + 2066
    21  CoreFoundation                      0x0000000103372431 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    22  CoreFoundation                      0x00000001033682fd __CFRunLoopDoSources0 + 269
    23  CoreFoundation                      0x0000000103367934 __CFRunLoopRun + 868
    24  CoreFoundation                      0x0000000103367366 CFRunLoopRunSpecific + 470
    25  GraphicsServices                    0x0000000105067a3e GSEventRunModal + 161
    26  UIKit                               0x0000000100ca1900 UIApplicationMain + 1282
    27  testapp                            0x000000010004964f main + 111
    28  libdyld.dylib                       0x00000001047ef145 start + 1
    29  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NoMethodError

================================================================================
The application terminated. A crash report file may have been generated by the
system, use `rake crashlog' to open it. Use `rake debug=1' to restart the app
in the debugger.
================================================================================

I've triple checked everything so I hope it's not a typo from my side. Thanks a lot for your help and your work on this brilliant gem.

markrickert commented 9 years ago

app.make_button is a method of RedAlert. Add gem "RedAlert" to your gemfile, bundle and try again... but also note that app.make_button is specifically meant for using alert views, so you'll need a bit more than what you have in your some_action method above to get it working.

andersennl commented 9 years ago

Thanks for your fast answer! That was it, the RedAlert gem was missing. Maybe this dependency could be mentioned in the docs: docs

squidpunch commented 9 years ago

sounds like we should require the redalert gem in the rakefile - since its listed as a runtime dependency.

Pushing a PR momentarily. thanks for pointing this out @andersennl