Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/102.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 如何确保图像在点击次数过多时不会消失?斯威夫特4_Ios_Swift_Variables_Integer - Fatal编程技术网

Ios 如何确保图像在点击次数过多时不会消失?斯威夫特4

Ios 如何确保图像在点击次数过多时不会消失?斯威夫特4,ios,swift,variables,integer,Ios,Swift,Variables,Integer,我正在开发一个应用程序,当你点击它时,我的图像会发生变化。但是,应用程序中有一个bug,如果你不小心在上面点击了太多次,图像就会完全消失。我想给变量integerValue设置一个最大值,这样它就可以防止它被进一步点击。有人能帮我用Swift 4给出答案吗? 这是代码 var integerValue = 1 最大值应为9 第一次更新变量时: @objc private func updateProgress() { integerValue += 1 if integerVa

我正在开发一个应用程序,当你点击它时,我的图像会发生变化。但是,应用程序中有一个bug,如果你不小心在上面点击了太多次,图像就会完全消失。我想给变量integerValue设置一个最大值,这样它就可以防止它被进一步点击。有人能帮我用Swift 4给出答案吗? 这是代码

var integerValue = 1
最大值应为9

第一次更新变量时:

@objc private func updateProgress() {
    integerValue += 1
    if integerValue < 10 {
     self.updateImage()
    UserDefaults.standard.set(integerValue-1, forKey: String(day))
    self.displayLabelScreen()
    }
@objc private func deleteProgress() {
        integerValue -= 1
        if integerValue > 0 {
            UserDefaults.standard.set(integerValue-1, forKey: String(day))
        self.updateImage()
        }
    }

鉴于您发布的代码以及需要将integerValue保持在1-9范围内,请按如下方式更新代码:

@objc private func updateProgress() {
    // Only increment if the new value will be 9 or less
    if integerValue < 9 {
        integerValue += 1
        self.updateImage()
        UserDefaults.standard.set(integerValue, forKey: String(day))
        self.displayLabelScreen()
    }
}

@objc private func deleteProgress() {
    // Only decrement if the new value will be 1 or more
    if integerValue > 1 {
        integerValue -= 1
        UserDefaults.standard.set(integerValue, forKey: String(day))
        self.updateImage()
    }
}

你需要提供更多的信息。显示更新integerValue的代码。如果您不希望它超过9,那么不要将其设置为高于9的值。谢谢您的建议!那么,你希望与你发布的代码有什么不同呢?在我制作的应用程序中,当我在图像上单击太多次时,图像将用完,图像将完全消失。我想为整数值设置一个最大值,这样它就不能被进一步点击。我将在问题中添加一段额外的代码,这可能有助于我获得答案。将增量/减量移动到if语句中,以便仅在当前有效的情况下对其进行更改。