分享按钮在SpriteKit中崩溃了吗?

时间:2017-06-30 08:00:46

标签: ios swift

所以我有一个分享按钮,它打开了UI-Activity。当我点击分享按钮时,它会崩溃并收到此错误:libc++abi.dylib: terminating with uncaught exception of type NSException。谁可以检查我的代码,看看发生了什么?谢谢 *最后一件事:当他们返回游戏时,分享按钮会停留在屏幕上。我怎样才能隐藏它,就像只在场景中的游戏中显示它一样?

  

这是我的代码

    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)




 }

1 个答案:

答案 0 :(得分:0)

如果函数pressed:GameOver类中,请不要将目标添加为self。而是将目标添加为GameOver

的对象
let objGameOver = // Get your existing GameOver class instance here
shareButton.addTarget(objGameOver, action: (#selector(GameOver.pressed(_:))), for: .touchUpInside)