Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios swift图像数组回码按钮错误_Ios_Swift - Fatal编程技术网

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])
}