我正在使用Swift 2.1开发Xcode7
我的代码有问题。我正在执行随机功能,当我触摸按钮时,它会自动向您显示随机电影。
但是问题是我想让我在触摸按钮时重复该功能,因为当我触摸按钮时,什么也没发生。
这是代码:
class ViewController: UIViewController {
var random = arc4random_uniform(3)
@IBOutlet weak var NomDuFilm: UILabel!
@IBOutlet weak var ImageFilm: UIImageView!
@IBAction func ShowRandom(sender: AnyObject) {
switch random {
case 0:
self.ImageFilm.image = UIImage(named: "Inception.jpg")
NomDuFilm.text = "Inception"
NomDuFilm.hidden = false
case 1:
self.ImageFilm.image = UIImage(named: "Memento.jpg")
NomDuFilm.text = "Memento"
NomDuFilm.hidden = false
case 2:
self.ImageFilm.image = UIImage(named: "ShutterIsland.jpg")
NomDuFilm.text = "Shutter Island"
NomDuFilm.hidden = false
case 3:
self.ImageFilm.image = UIImage(named: "Prisoners.jpg")
NomDuFilm.text = "Prisoners"
NomDuFilm.hidden = false
case 4:
self.ImageFilm.image = UIImage(named: "LePrestige.jpg")
NomDuFilm.text = "Le Prestige"
NomDuFilm.hidden = false
default:
self.ImageFilm.image = UIImage(named: "PulpFiction.png")
NomDuFilm.text = "Pulp Fiction"
NomDuFilm.hidden = false
}
谢谢您的帮助,也很抱歉我的英语水平...
最佳答案
您是否在行动通话中添加了随机通话?
@IBAction func ShowRandom(sender: AnyObject) {
random = arc4random_uniform(3)
//switch goes here.
}