调用 IBAction 中的 IBAction 按钮



我得到了这个IBAction,可以随机洗一包牌

@IBAction func playRoundTapped(sender: UIButton) {
    cardNamesArray = GKRandomSource.sharedRandom().arrayByShufflingObjectsInArray(cardNamesArray) as! [String]
    cardNamesArray2 = GKRandomSource.sharedRandom().arrayByShufflingObjectsInArray(cardNamesArray2) as! [String]

    let firstCardString:String = self.cardNamesArray[0]
    self.FirstCardImageView.image = UIImage(named: firstCardString)
    let SecondCardString:String = self.cardNamesArray2[1]
    self.SecondCardImageView.image = UIImage(named: SecondCardString)
    }

。当牌匹配时,这部分代码会得分,但是当它们 macle 时,我需要它再次洗牌。我可以在 IBAction snapButtonTappeded 中使用 IBAction playRoundTap 吗?

@IBAction func SnapButtonTapped(sender: UIButton) {

        if firstRandomNumber == SecondRandomNumber {
        print("index match")
        self.playerScore += 1
        self.playerScoreLabel.text = String(self.playerScore)
        cardNamesArray.removeAtIndex(firstRandomNumber)
        cardNamesArray2.removeAtIndex(SecondRandomNumber)
            if cardNamesArray.count == 0 && cardNamesArray2.count == 0{

                print("user won")
                //alert box
                let alert = UIAlertController(title:"Level completed", message: "Your score is (playerScore)", preferredStyle: UIAlertControllerStyle.Alert)
                alert.addAction(UIAlertAction(title:"next level", style: UIAlertActionStyle.Default, handler: nil))
                    self.presentViewController(alert, animated:true, completion:nil)
            }
    }

是的,你可以。IBAction 只是一个具有特定签名和标记的方法,它告诉接口生成器它可以连接到控件。您可以自由地自己称呼它。

最新更新