我试图有两个由If语句触发的segue。这是我到目前为止的编码。
func prepareForSegue(segue:UIStoryboardSegue,AnyObject?){
if segue.identifier == "SomeoneWon" {
var ThirdVC: WinnerViewController = segue.destinationViewController as! WinnerViewController
ThirdVC.WinnerName = Winner}
else if segue.identifier == "PopUp" {
var PopUpVC: PopUpViewController = segue.destinationViewController as! PopUpViewController
PopUpVC.RoundWinnerPop = RoundWinner}
If语句如下:
if firstrandomnumber > secondrandomnumber && firstrandomnumber > thirdrandomnumber && firstrandomnumber > fourthrandomnumber {
Player1ScoreTotal += 1
self.Player1Score.text = String(Player1ScoreTotal)
Winner = receivedString1
RoundWinner = receivedString1
if Player1ScoreTotal == 5{
performSegueWithIdentifier("SomeoneWon", sender: UIButton())}
else {
performSegueWithIdentifier("PopUp", sender: UIButton()) }}
else if secondrandomnumber > firstrandomnumber && secondrandomnumber > thirdrandomnumber && secondrandomnumber > fourthrandomnumber {
Player2ScoreTotal += 1
self.Player2Score.text = String(Player2ScoreTotal)
Winner = receivedString2
RoundWinner = receivedString2
if Player2ScoreTotal == 5{
performSegueWithIdentifier("SomeoneWon", sender: UIButton())}
else {
performSegueWithIdentifier("PopUp", sender: UIButton())}}
else if thirdrandomnumber > firstrandomnumber && thirdrandomnumber > secondrandomnumber && thirdrandomnumber > fourthrandomnumber {
Player3ScoreTotal += 1
self.Player3Score.text = String(Player3ScoreTotal)
Winner = receivedString3
RoundWinner = receivedString3
if Player3ScoreTotal == 5{
performSegueWithIdentifier("SomeoneWon", sender: UIButton())}
else{
performSegueWithIdentifier("PopUp", sender: UIButton())}}
else if fourthrandomnumber > firstrandomnumber && fourthrandomnumber > secondrandomnumber && fourthrandomnumber > thirdrandomnumber {
Player4ScoreTotal += 1
self.Player4Score.text = String(Player4ScoreTotal)
Winner = receivedString4
RoundWinner = receivedString4
if Player4ScoreTotal == 5{
performSegueWithIdentifier("SomeoneWon", sender: UIButton())
}
else{
performSegueWithIdentifier("PopUp", sender: UIButton())}}
}
segue有效,但变量的信息不会被转移,即假设显示“Winner”和“RoundWinner”值的标签保持空白。我是新人,所以我希望错误很简单。感谢。