문제

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)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top