Iphone 禁用按钮不会';行不通
我有一个按钮,在调用此方法时要禁用该按钮:Iphone 禁用按钮不会';行不通,iphone,ios,objective-c,xcode,Iphone,Ios,Objective C,Xcode,我有一个按钮,在调用此方法时要禁用该按钮: - (void)disableSendButton { NSLog(@"disableSendButton method"); self.sendBtn.enabled = NO; //[self.sendBtn setEnabled:NO]; } 来自按钮的头文件属性:@property(强,非原子)IBOutlet UIButton*sendBtn
- (void)disableSendButton
{
NSLog(@"disableSendButton method");
self.sendBtn.enabled = NO;
//[self.sendBtn setEnabled:NO];
}
来自按钮的头文件属性:@property(强,非原子)IBOutlet UIButton*sendBtn我还合成了它
disableSendButton方法
打印出来,但按钮保持启用状态。。。这很奇怪,我不知道该怎么解决。ViewController称为sendViewController,我在程序的其他地方执行此操作[sendViewController.sendBtn setEnabled:NO]代码>,这就像预期的一样。除此之外,我不启用或禁用该按钮
编辑:
sendViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SendView"];
if(self.sendButtonIsEnabled == NO){
//sendViewController.sendBtn.enabled = NO; // Doesn't work
//[sendViewController.sendBtn setEnabled:NO]; // Doesn't work
[sendViewController disableSendButton];
}
调用ViewDidLoad中的方法
self.sendBtn.enabled = NO;
您可以尝试记录您的self.sendBtn
,查看它是否为零。可能您在视图加载完成之前发送了此消息。您是否已将插座连接到IB中的实际按钮?我已将按钮连接到故事板。您可以尝试此操作<代码>sendBtn.enabled=否代码>按钮为零,但我将其与故事板连接?可能是因为在加载按钮之前调用了该方法?我怎样才能解决这个问题?