首页 > 解决方案 > 我想在按右键时浏览数组,按左键时反转数组

问题描述

此代码针对数组中的下一项运行,但是当 leftButtonWasClciked 时,它会给出错误

  @IBAction func rightButtonWasClicked(_ sender: Any) {
        
        NTimeLabel.text = NTimeArrayRemasterd[currentIndex] // Set the text to the element at currentIndex in the array
        currentIndex = currentIndex + 1 == NTimeArrayRemasterd.count ? 0 : currentIndex + 1 // Increment currentIndex
        
    }
@IBAction func leftButtonWasClicked(_ sender: Any) {
    NTimeLabel.text = NTimeArrayRemasterd[currentIndex] // Set the text to the element at currentIndex in the array
    currentIndex = currentIndex - 1 == NTimeArrayRemasterd.count ? 0 : currentIndex - 1 // Decrement currentIndex
}

按下左右按钮时正确导航

标签: iosswift

解决方案


推荐阅读