gpt4 book ai didi

ios - Rubymotion 图像按钮事件未触发

转载 作者:行者123 更新时间:2023-11-28 22:50:31 28 4
gpt4 key购买 nike

有谁知道为什么以下 RubyMotion 代码中的按钮在单击时不会触发 say_something 方法...

class HomeViewController < UIViewController
def loadView
self.view = UIImageView.alloc.init
end

def viewDidLoad
view.image = UIImage.imageNamed('background.png')

@action_button = UIButton.buttonWithType UIButtonTypeCustom
@action_button.frame = [[100, 100], [224, 229]]
@action_button.setBackgroundImage(UIImage.imageNamed("home_button_green.png"), forState: UIControlStateNormal)
@action_button.addTarget(self, action: :say_something, forControlEvents: UIControlEventTouchUpInside)

view.addSubview @action_button
end

def say_something
@alert_box = UIAlertView.alloc.initWithTitle("Hello World",
message:"Hi",
delegate: nil,
cancelButtonTitle: "ok",
otherButtonTitles:nil)

# Show it to the user
@alert_box.show
end

def viewDidAppear(animated)

end


end

最佳答案

我找到了答案,需要告诉 View 允许用户交互......

view.userInteractionEnabled = true

这解决了问题,现在按下按钮并触发事件。

关于ios - Rubymotion 图像按钮事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12090028/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com