2017-06-30 3 views
0

だから、UIアクティビティを開く共有ボタンがあります。共有ボタンをクリックするとクラッシュし、このエラーが表示されます:libc++abi.dylib: terminating with uncaught exception of type NSException。誰かが自分のコードをチェックして、何が起こっているか見ることができますか?ありがとう *最後のものも1つ:ゲームに戻ったときに共有ボタンが画面に残ります。私はそれを隠すことができますか?ゲームオーバーシーンでしか表示しないでください。SpriteKitで共有ボタンがクラッシュしていますか?

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) 




} 
+0

「GameOver」とは何ですか?それはクラスですか? – Bali

+0

はい、あなたがself.present(activityVC、animated:true、completion:nil)を使ってそのactivityVCを提示していないのは、クラス –

+0

です。 – KKRocks

答えて

-1

機能pressed:GameOverクラス内にある場合、selfとしてターゲットを追加しないでください。代わりにGameOverクラスのオブジェクトとしてターゲットを追加してください

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

私にコードを教えてもらえますか? 'shareButton.addTarget(self、action:(" pressed: ")for::.touchUpInside)' 答えを更新します –

+0

objGameOverは「独自の初期値で使用される変数」と言っていますか? –

+0

いいえ、既存のクラスを取得する必要があります。ここで 'GameOver'クラスの目的は何ですか?あなたはすでにそのクラスのインスタンスを作成していますか?それは 'UIViewController'ですか? – Bali

関連する問題