IOS:具有两个操作的 IBAction

发布于 2024-12-10 16:18:29 字数 375 浏览 0 评论 0原文

在我的应用程序中,我有一个 ibaction,其中有 2 条不同的指令,其中有一个“if”,

 if (i == 0)  //do instruction set 1
 if (i == 1) //do instruction set 2
 // and everytime I push button i change from 0 to 1 or from 1 to 0

问题是,如果我重复按下此 IbAction 的按钮,它就无法正常工作,因为前一个 ibaction 未完成其指令集1

示例=按下按钮,它执行指令集1,如果我再次按下该按钮,它不应该工作,因为它没有完成其工作,并且我想等待指令集1结束以重复按下按钮。

你明白吗?

In my app I have an ibaction and inside it I have 2 different instruction with an "if"

 if (i == 0)  //do instruction set 1
 if (i == 1) //do instruction set 2
 // and everytime I push button i change from 0 to 1 or from 1 to 0

the problem is that if I repeatedly press the button of this IbAction it don't work fine because the previous ibaction didn't finish its instruction set1

example = press button, it execute instruction set 1, if I push another time the button it shouldn't work because it it didn't finish its work and I want to wait the end of instruction set 1 to repeat the push of button.

Do you understand?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

穿越时光隧道 2024-12-17 16:18:29

假设您的类中有 BOOL workInProgress 变量:

- (IBAction)action {
    if (!workInProgress) {
        workInProgress = YES;
        if (i == 0) {
            // do something that in the end sets workInProgress to NO
        } else if (i == 1) {
            // do something else that in the end sets workInProgress to NO
        }
    }
}

Assuming you have BOOL workInProgress variable in your class:

- (IBAction)action {
    if (!workInProgress) {
        workInProgress = YES;
        if (i == 0) {
            // do something that in the end sets workInProgress to NO
        } else if (i == 1) {
            // do something else that in the end sets workInProgress to NO
        }
    }
}
记忆で 2024-12-17 16:18:29

使用布尔值,在指令集开始时将其设置为 NO,然后返回 YES。如果该值为 NO,则不执行任何操作

use a bool value,set it to NO at the begining of your instruction set,and back to YES after.if the value is NO then don't do anythig

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文