【问题标题】:UIButton will not disable when referenced from IBOutlet but does when referenced from IBActionUIButton 在从 IBOutlet 引用时不会禁用,但在从 IBAction 引用时会禁用
【发布时间】:2012-05-15 17:21:17
【问题描述】:

我已经检查了好几次,以确保我在 IB 中的连接是正确的。

// This does not work
UIButton *additionButton = [self.gameShopCoinButtonCollection objectAtIndex:0];
additionButton.enabled = NO;

// This does work
-(IBAction)gameShopBuyButtonPressed:(UIButton *)sender {
    sender.enabled = NO;
}

【问题讨论】:

  • [self.gameShopCoinButtonCollection objectAtIndex:0];return 不是 nil 对象吗?
  • 返回nil,但是显示在IB中是连接的。
  • 尝试使用直接引用而不是集合。它应该可以节省您的时间。
  • 直接引用了还是nil
  • 属性(强,非原子) IBOutlet UIButton *gameButtonAdditionCoins;合成gameButtonAdditionCoins = _gameButtonAdditionCoins;我还有什么遗漏的吗?

标签: objective-c xcode uibutton


【解决方案1】:

禁用 -

additionButton.userInteractionEnabled = NO;

【讨论】:

    【解决方案2】:

    您无法保证 IBOutletCollection 中项目的顺序。您需要直接引用该按钮并以这种方式禁用它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 2023-04-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多