I've got a controller and a button. When the button is clicked, I want to show an UIAlertView
. What I can't get to work is the UIBarButtonItem
's action parameter.
In my controller
class TapController < UIViewController
def alert
alert = UIAlertView.new
alert.message = "It's working"
alert.show
end
def viewDidLoad
super
self.view.backgroundColor = UIColor.whiteColor
right_button = UIBarButtonItem.alloc.initWithTitle("Go Deeper",
style:UIBarButtonItemStyleBordered,
target:self,
action:'alert')
self.navigationItem.rightBarButtonItem = right_button
end
end
My app/app_delegate.rb
:
class AppDelegate
def application(application, didFinishLaunchingWithOptions:launchOptions)
#UIScreen is the display the app runs on
@window = UIWindow.new.initWithFrame(UIScreen.mainScreen.bounds)
@window.makeKeyAndVisible
controller = TapController.alloc.initWithNibName(nil, bundle: nil)
@window.rootViewController = UINavigationController.alloc.initWithRootViewController(controller)
true
end
end
So it's very simple, but the UIBarButtonItem's target or action attributes doesn't work as expected.
Here's your problem. In your app delegate, you need to call alloc
instead of new
on UIWindow
.
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)