我有一个控制器和一个按钮。当点击按钮时,我想显示一个UIAlertView
。我不能工作的是UIBarButtonItem
的action参数。
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
它很简单,但是UIBarButtonItem的target或action属性没有像预期的那样工作
你的问题是。在你的app委托中,你需要在UIWindow
上调用alloc
而不是new
。
@window = UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)