【问题标题】:Disable a button in xcode禁用xcode中的按钮
【发布时间】:2011-11-17 21:26:53
【问题描述】:

在我的项目中,我有一个通过 IBOutlet 调用函数的按钮,我需要知道如何输入函数代码以禁用按钮,因为我识别按钮(使用标签?)
还有要写什么?

【问题讨论】:

    标签: iphone objective-c cocoa-touch ipad uibutton


    【解决方案1】:

    我想你有点困惑。您的按钮通过 IBAction 连接到方法。您需要为您的按钮创建一个@property 并通过 IBOutlet 将其连接到 IB。

    或者,您可以使用 IBAction 中的 sender 参数。可能是这样的……

    - (IBAction)buttonPressed:(id)sender
    {
        UIButton *buttonThatWasPressed = (UIButton *)sender;
        buttonThatWasPressed.enabled = NO;
    }
    

    【讨论】:

      【解决方案2】:

      很简单。

      self.yourButton.enabled = NO;
      

      【讨论】:

      • 是的,但我不知道我在 IB 中创建的按钮的名称
      • 您需要在头文件中定义一个 IBOutlet。 'IBOutlet NSButton *myButton'。将插座连接到 Interface Builder 中的按钮。最后,在您的实现中,您可以使用“myButton”引用按钮(例如“myButton.enabled = NO”)。
      【解决方案3】:

      为此制作这样的代码

      button.enabled=NO;
      

      &如果你想再次启用它,像这样的代码

      button.enabled=YES;
      

      【讨论】:

        猜你喜欢
        • 2010-10-08
        • 1970-01-01
        • 1970-01-01
        • 2017-04-11
        • 1970-01-01
        • 1970-01-01
        • 2015-01-02
        • 1970-01-01
        • 2018-09-30
        相关资源
        最近更新 更多