dimanche 1 février 2015

simple swift code doesn't work

Why doesn't my code work? In my app there are two buttons "next", "solution" and also an UIImageview. When you press Next a new Problem comes up as an image, if you press solution the solution comes up.. the problems are images saved under card1,card2....etc and the solution under Sol1,Sol2 etc.. It is important that if Problem 2 comes up (card2) the solution 2 is displayed and not i.e. solution 1


import UIKit


class ViewController2: UIViewController {



@IBOutlet weak var Image1: UIImageView!
@IBOutlet weak var Solutionbutton: UIButton!
@IBOutlet weak var nextbutton: UIButton!

var randomNumber:Int = 0
var cardString:String = ""
var solutionString:String = ""

@IBAction func nextbutton(sender: AnyObject) {

//Randomize a number for the first imageview
var randomNumber = arc4random_uniform(2) + 1

//Construct a string with the random number
self.cardString = String(format: "card%i",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.
}

override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}



Aucun commentaire:

Enregistrer un commentaire