如何隐藏或禁用与相同IBAction和不同标签连接的按钮swift 4.2

时间:2018-10-20 08:19:39

标签: ios button properties ios12 swift4.2

我正在尝试创建一个显示问题的测验应用,然后用户将通过按下两个按钮[true / false]中的一个来选择答案,然后按next按钮移至下一个问题。

我要隐藏答案按钮或在用户选择其中一个按钮后将其禁用,然后出现nextButton。

这两个答案按钮与相同的IBAction连接在一起,但具有不同的标签[1表示“真​​”按钮,2表示“假”按钮),该按钮(下一个)与另一个IBAction连接。

我无法访问按钮属性的问题!

它尝试了

#include <type_traits>

struct enemy;  // We need a forward declaration of your enemy

struct my_class {

    // The access is done using a factory, where the caller has to tell
    // us his own name
    template <class T>
    struct make{
        static_assert(!std::is_same<T,enemy>::value,"you are my enemy.");
        friend T;
    private:
        my_class operator() () { return my_class{}; }
    };


private:
    my_class(); // This is the constructor we care about

};

struct no_enemy {
    void bar() {
        my_class a = my_class::make<no_enemy>{}();  // works
    }
};


struct enemy {
    void bar() {
        my_class b = my_class::make<enemy>{}();     // error: static_assert failed
        my_class c = my_class::make<no_enemy>{}();  // error: foo is "private"
    }
};

但是每次我打印按钮名称后跟一个点时,我都没有建议,xcode会给我错误“在'后面的预期成员名称。' ” 我唯一的建议是:

answerPressed.isEnabled = false

这是应用程序的完整代码,任何帮助请:)

 answerPressed(sender: AnyObject)

ViewController类:UIViewController {

import UIKit

}

谢谢

1 个答案:

答案 0 :(得分:0)

很抱歉,如果我误解了这个问题。听起来好像您想在按下真假按钮后禁用其中之一。但是,我在您的IBOutlet变量列表中都没有看到它们。您不能直接引用它们,因为类不知道它们。

在answerPressed函数中,您可以使用发件人引用来禁用发件人(“真”或“假”按钮),但不能禁用未选中的发件人。

我怀疑您需要做的就是为您的真假按钮创建IBOutlets,将它们映射到视图,然后您可以对它们进行操作。