swift 如何有选择地显示每张卡片的解法?
swift how to display solution for each card selectively?
在我的应用程序中,我有一个“下一步”按钮和一个“解决方案”按钮。当您按下一个新卡片时,会出现一张新卡片(即 Image card1),如果您再次按下一个卡片,则会随机出现另一张卡片。我的问题是如何有选择地显示每张卡片的解决方案(即对于 card1 有 sol1)
@IBAction func nextbutton(发件人:AnyObject){
//Randomize a number for the first imageview
var firstRandomNumber = arc4random_uniform(2) + 1
//Construct a string with the random number
var firstCardString:String = String(format: "card%i", firstRandomNumber)
// Set the first card image view to the asset corresponding to the randomized number
self.Image1.image = UIImage(named: firstCardString)
}
@IBAction func solutionbutton(sender: AnyObject) {
}
我附上了你的 problem.The 代码问题的完整示例是你在下一个按钮中创建的变量范围有限,我们希望解决方案具有相同的随机无值 card.Now 它们超出了下一个操作的范围,只需使用关键字 self
即可在此 class 中轻松访问它们
import UIKit
class YourViewController : UIViewController {
var randomNumber:Int = 0
var cardString:String = ""
var solutionString:String = ""
@IBAction func nextbutton(sender: AnyObject) {
//Randomize a number for the first imageview
self.randomNumber = arc4random_uniform(2) + 1
//Construct a string with the random number
self.cardString = String(format: "card%i", self.randomNumber)
self.solutionString = String(format: "sol%i", self.randomNumber)
// Set the first card image view to the asset corresponding to the randomized number
self.Image1.image = UIImage(named: self.cardString)
}
@IBAction func solutionbutton(sender: AnyObject) {
self.Image1.image = UIImage(named: self.solutionString)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
在我的应用程序中,我有一个“下一步”按钮和一个“解决方案”按钮。当您按下一个新卡片时,会出现一张新卡片(即 Image card1),如果您再次按下一个卡片,则会随机出现另一张卡片。我的问题是如何有选择地显示每张卡片的解决方案(即对于 card1 有 sol1)
@IBAction func nextbutton(发件人:AnyObject){
//Randomize a number for the first imageview
var firstRandomNumber = arc4random_uniform(2) + 1
//Construct a string with the random number
var firstCardString:String = String(format: "card%i", firstRandomNumber)
// Set the first card image view to the asset corresponding to the randomized number
self.Image1.image = UIImage(named: firstCardString)
}
@IBAction func solutionbutton(sender: AnyObject) {
}
我附上了你的 problem.The 代码问题的完整示例是你在下一个按钮中创建的变量范围有限,我们希望解决方案具有相同的随机无值 card.Now 它们超出了下一个操作的范围,只需使用关键字 self
即可在此 class 中轻松访问它们import UIKit
class YourViewController : UIViewController {
var randomNumber:Int = 0
var cardString:String = ""
var solutionString:String = ""
@IBAction func nextbutton(sender: AnyObject) {
//Randomize a number for the first imageview
self.randomNumber = arc4random_uniform(2) + 1
//Construct a string with the random number
self.cardString = String(format: "card%i", self.randomNumber)
self.solutionString = String(format: "sol%i", self.randomNumber)
// Set the first card image view to the asset corresponding to the randomized number
self.Image1.image = UIImage(named: self.cardString)
}
@IBAction func solutionbutton(sender: AnyObject) {
self.Image1.image = UIImage(named: self.solutionString)
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}