Ios swift图像数组回码按钮错误
我想从图片上滑下来。我的代码是:Ios swift图像数组回码按钮错误,ios,swift,Ios,Swift,我想从图片上滑下来。我的代码是: @IBOutlet weak var image: UIImageView! var resimler=["01.jpg","02.jpg","03.jpg","04.jpg","05.jpg"] var index=0 override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view, typically fr
@IBOutlet weak var image: UIImageView!
var resimler=["01.jpg","02.jpg","03.jpg","04.jpg","05.jpg"]
var index=0
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
@IBAction func gerileBttn(sender: UIButton) {
index--
if index==resimler.count {index=0}
image.image=UIImage(named: resimler[index])
}
@IBAction func ilerle(sender: UIButton) {
index++
if index==resimler.count {index=0}
image.image=UIImage(named: resimler[index])
}
当我按下向前移动的图片。但是,当涉及到第一张图片时,当我按下back键时,数组错误,程序是否崩溃。。
我怎样才能解决这个问题。
感谢您的帮助。看起来您的指数可能会变为负值。也许这个假设你想把它包起来
@IBAction func gerileBttn(sender: UIButton) {
index--
if index<0 {index=resimler.count-1}
image.image=UIImage(named: resimler[index])
}