2012-11-02 63 views
1

我有一个动态初始化的按钮..我想从另一个UIViewController禁用该按钮。从xcode中的另一个视图控制器禁用按钮

我使用这个代码:

按钮是 @property(强,非原子)IBOutlet中的UIButton *关于我们;

,然后我尝试禁用这样说:

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

但按钮依然会启用..任何想法,为什么?

+0

该按钮尚未加载,因为该视图尚不存在。它将加载到OtherViewController的viewDidLoad中。正如EIJay所说,这就是为什么你需要设置一个标志,然后使用该标志禁用viewDidLoad中的按钮。 – yuf

+0

有道理感谢您的帮助 – user1767928

回答

1

你需要一个公共BOOL属性:

@property(nonatomic) buttonEnabled; 

OtherViewController。将该值设置为任意值(YES或NO),然后在viewDidLoad中:

aboutus.enabled = buttonEnabled; 
相关问题