【问题标题】:disable button from another view controller in xcode禁用xcode中另一个视图控制器的按钮
【发布时间】:2012-10-23 16:01:37
【问题描述】:

我有一个动态初始化的按钮。我想从另一个 UIViewController 禁用该按钮。

我正在使用此代码:

按钮是 @property(强,非原子)IBOutlet UIButton *aboutus;

然后我尝试以这种方式禁用它:

OtherViewController * view2 = [[OtherViewController alloc]      initWithNibName:@"view2"    bundle:nil];
view2.aboutus.enabled=NO;

但该按钮仍会启用.. 任何想法为什么?

【问题讨论】:

  • 按钮尚未加载,因为视图尚不存在。它将加载到 OtherViewController 的 viewDidLoad 中。这就是为什么您需要设置一个标志,然后使用该标志来禁用 viewDidLoad 中的按钮,正如 EIJay 所说。
  • 有道理感谢您的帮助

标签: ios xcode uiviewcontroller uibutton


【解决方案1】:

您需要一个公开的BOOL 属性:

@property(nonatomic) buttonEnabled;

在OtherViewController。将该值设置为您想要的任何值(是或否),然后在 viewDidLoad 中:

aboutus.enabled = buttonEnabled;

【讨论】:

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