IOS 8 xCode 6按钮显示为已禁用,但未禁用

IOS 8 xCode 6按钮显示为已禁用,但未禁用,ios,objective-c,uibutton,Ios,Objective C,Uibutton,环境:IOS 8.02 Xcode 6 我在故事板上有一张表格。它有两个标签、一个文本框和两个按钮。 btnValidateAndSave禁用表单上的所有其他控件并调用web服务 BTNCE变为灰色,好像它已被禁用,但它是可单击的 下面是表单背后的实际代码 #import "vcDigitalKeyManager.h" #import "serviceManager.h" #import "eziEnums.h" #import "IsSystemLockedMethod.h" #import

环境:IOS 8.02 Xcode 6

我在故事板上有一张表格。它有两个标签、一个文本框和两个按钮。 btnValidateAndSave禁用表单上的所有其他控件并调用web服务

BTNCE变为灰色,好像它已被禁用,但它是可单击的

下面是表单背后的实际代码

#import "vcDigitalKeyManager.h"
#import "serviceManager.h"
#import "eziEnums.h"
#import "IsSystemLockedMethod.h"
#import "eziResponse.h"

@interface vcDigitalKeyManager ()
- (IBAction)btnValidateAndSave:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *txtDigitalKey;
@property (strong, nonatomic) IBOutlet UILabel *lblErrorMessage;
@property (strong, nonatomic) IBOutlet UIActivityIndicatorView *lblValidateActivity;
@property (strong, nonatomic) IBOutlet UIButton *btnValidateAndSave;
@property (strong, nonatomic) IBOutlet UIButton *btnCancel;
@property (strong, nonatomic) NSNumber *isWorking;

- (IBAction)btnCancel:(id)sender;

@end

@implementation vcDigitalKeyManager

@synthesize txtDigitalKey = _txtDigitalKey;
@synthesize lblErrorMessage = _lblErrorMessage;
@synthesize btnCancel = _btnCancel;


- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.lblValidateActivity setHidden:true];

}

- (IBAction)btnValidateAndSave:(id)sender {

    [self.txtDigitalKey resignFirstResponder];
    [self.txtDigitalKey setEnabled:NO];
    [self.txtDigitalKey setUserInteractionEnabled:NO];

    [self.lblValidateActivity setHidden:NO];

    [self.btnValidateAndSave setEnabled:NO];
    [self.btnValidateAndSave setUserInteractionEnabled:NO];

    [self.txtDigitalKey setEnabled:NO];
    [self.txtDigitalKey setUserInteractionEnabled:NO];

    self.btnCancel.enabled=NO;
    self.btnCancel.userInteractionEnabled = NO;

    [self.lblValidateActivity startAnimating];

    _isWorking = [NSNumber numberWithInt:1];

    NSString * requestBody = [serviceManager buildSoapMessage:IsSystemLocked :self.txtDigitalKey.text ];

    [[NSNotificationCenter defaultCenter] addObserver:self
                                             selector:@selector(displayEziResponse:)
                                                 name:@"kIsSystemLockedResponseNotification"
                                               object:nil];

     [[[IsSystemLockedMethod alloc]init] callNonPciMethod:requestBody servicetype:NonPci];

}

- (void) displayEziResponse:(NSNotification *) notification{

    NSDictionary *userInfo = notification.userInfo;
    eziResponse *myResponse = [userInfo objectForKey:@"someKey"];

    if([myResponse.ErrorNumber isEqual:@"0"])
    {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    else
    {
        [self.lblErrorMessage setText:[NSString stringWithFormat:@"%@: %@",myResponse.ErrorNumber, myResponse.ErrorMessage]];
        [self.lblErrorMessage setTextColor:[UIColor redColor]];
        [self.lblErrorMessage setHidden:NO];

        [self.lblValidateActivity stopAnimating];
        [self.lblValidateActivity setHidden:YES];

        [self.btnValidateAndSave setEnabled:YES];
        [self.btnValidateAndSave setUserInteractionEnabled:YES];

        [self.txtDigitalKey setEnabled:YES];
        [self.txtDigitalKey setUserInteractionEnabled:YES];

        [self.btnCancel setEnabled:YES];
        [self.btnCancel setUserInteractionEnabled:YES];

    }



}

- (IBAction)btnCancel:(id)sender {

    //NSLog([NSString stringWithFormat:@"%d",NSStringFromBOOL(BOOL self.btnCancel.enabled)]);

    if(_isWorking == [NSNumber numberWithInt:0])
    {
            [self dismissViewControllerAnimated:YES completion:nil];
    }
    //if(self.btnCancel.enabled)

}
@end
我已经在模拟器和iPhone 5S上对此进行了测试
您知道如何实际禁用按钮吗?

更喜欢禁用按钮上的用户交互

[self.btnCancel setUserInteractionEnabled:NO];

我发现了问题,而实际上问题不在于按钮

Validate and Save按钮调用对web服务进行异步调用的函数

我使用通知让主线程知道何时收到响应

通知正在后台线程上发回。其影响是取消按钮被实时启用,而不是视觉状态


我修改了代码,以便将通知发送回主线程,现在主线程上的所有内容都会在1秒内更新。

我确信它已连接,否则不会变为灰色。@wilkeit ok!然后尝试禁用按钮上的用户交互,就像我在上面的答案中所做的那样:顺便说一句,我更新了我的答案!我已经更新了描述,并从表格后面提供了完整的代码。我还更新了代码以匹配您的建议,但仍然没有成功。我做了一个测试并添加了一个名为IsWorking的属性,我在单击BtnValidate和Save按钮时更改了该值。我在单击btnCancel时检查该值,因为它不匹配,所以停止。但是,按钮再次变为绿色。这可能与它是一个模态序列这一事实有关吗?此外,我尝试使用控制消息传递和点符号,但这两个选项都不起作用。它几乎像是在一条单独的线上。