按下按钮滚动数组,我的应用程序崩溃

时间:2017-06-28 22:09:56

标签: arrays swift button uiimageview

当我在模拟器中按nextImage1时,我收到错误消息:

  

[Project_BodySwapp.ViewController nextImage:]:无法识别的选择器发送到实例0x7ffe4660a1e0'

import UIKit

class ViewController: UIViewController {

var imageNames1 = ["doghead","uk"]
var imageNames2 = ["macawLower","us"]
var pickedImage = String()
var currentImage = 0

@IBOutlet weak var displayImage: UIImageView!
//212x138
@IBOutlet weak var displayImage2: UIImageView!
//212x334


//BUTTON FUNCTIONALITY
//UPPER
@IBAction func randomizeImage(_ sender: Any) {
    displayImage.image = UIImage(named: (produceRandomValue(imageNames1)))
}

@IBAction func nextImage1(_ sender: Any) {
    currentImage += 1
    displayImage.image = UIImage(named: imageNames1[currentImage])
}

@IBAction func previousImage1(_ sender: Any) {


}



//LOWER
@IBAction func randomizeImage2(_ sender: Any) {

    displayImage2.image = UIImage(named: (produceRandomValue(imageNames2)))
}



func randomFromZero(to number: Int) -> Int {
    return Int(arc4random_uniform(UInt32(number)))
}

func produceRandomValue(_ array: [String]) -> String {
    let randomIndex = randomFromZero(to: array.count)
    let pickedImage = imageNames1[randomIndex]
    return pickedImage
}


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.
}


}

非常感谢任何帮助

1 个答案:

答案 0 :(得分:2)

您的按钮操作touchUpInside已设置为nextImage,但在您的代码中您没有。你改为nextImage1。重新检查Connections Inspector。

enter image description here