所以我有一个共享按钮,它可以打开 UI-Activity。当我单击共享按钮时,它崩溃并收到以下错误:libc++abi.dylib:因未捕获的 NSException 类型异常而终止
。任何人都可以检查我的代码并看看发生了什么事吗?谢谢
*最后一件事:当他们返回游戏时,共享按钮保留在屏幕上。我怎样才能隐藏它,比如只在游戏结束场景中显示它?
here is my code
shareButton = UIButton(frame: CGRect(x: 0, y:0, width: view.frame.size.width / 3, height: 60))
// shareButton.center = CGPoint(x: self.size.width/4, y: self.size.height/4)
shareButton.center = CGPoint(x: view.frame.size.width / 2 - 70, y: view.frame.size.height / 1.275)
shareButton.center = CGPoint(x: self.frame.midX, y: 3*self.frame.height/4)
shareButton.setTitle("Share", for: UIControlState.normal)
shareButton.setTitleColor(UIColor.white, for: UIControlState.normal)
shareButton.addTarget(self, action: (#selector(GameOver.pressed(_:))), for: .touchUpInside)
// shareButton.removeFromSuperview()
self.view?.addSubview(shareButton)
func pressed(_ sender: UIButton!) {
let va = self.view?.window?.rootViewController
let myText = "Can you beat my score \(score) in the game of Balls"
let activityVC:UIActivityViewController = UIActivityViewController(activityItems: [myText], applicationActivities: nil)
va?.present(activityVC, animated: true, completion: nil)
}
最佳答案
如果函数 pressed:
位于 GameOver
类中,请勿将目标添加为 self
。而是将目标添加为 GameOver
类
let objGameOver = // Get your existing GameOver class instance here
shareButton.addTarget(objGameOver, action: (#selector(GameOver.pressed(_:))), for: .touchUpInside)
关于ios - SpriteKit 中的分享按钮崩溃了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44841549/