環境:IOS 8.02 Xcode 6IOS 8 xCode 6按鈕顯示禁用,但不是
我在StoryBoard上有一個窗體。它有2個標籤,一個文本框和2個按鈕。 btnValidateAndSave禁用窗體上的所有其他控件並調用Web服務。
btnCance變灰,好像它已被禁用,但它是可點擊的。
下面是表單背後的實際代碼。
#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 任何想法測試該如何實際禁用按鈕?
我敢肯定,它的連線,否則它不會變成灰色。 – WilkieIT 2014-09-28 22:40:22
@WilkieIT好的!然後嘗試禁用按鈕上的userInteraction,就像我在上面做的答案:)我更新了我的答案btw! – 2014-09-28 22:48:22
我已經更新了描述並從表單後面提供了完整的代碼。我也更新了代碼,以符合你的建議,但仍然沒有運氣。 – WilkieIT 2014-09-29 10:06:23