你好我正在這個應用程序有一個登錄部分。我想要的是當我點擊登錄按鈕時,該按鈕必須是無法點擊的,直到登錄成功或失敗。我已經嘗試添加這條線doLogin.enabled = NO;
但這沒有用。請幫忙。這是我的代碼:登錄時禁用(登錄)按鈕
- (IBAction)doLogin:(id)sender {
[self loginUser];
}
- (void)loginUser
{
if (![self.usernameBox.text isEqualToString:@""] && ![self.passwordBox.text isEqualToString:@""])
{
//TODO: check id email pattern is correct
[self showLoginProcess:true];
[[AuthSingleton getInstance] attemptLoginWithUsername:self.usernameBox.text andPassword:self.passwordBox.text withSuccesBlock:^(AFHTTPRequestOperation *operation, id responseObject)
{
[self showLoginProcess:false];
UIViewController *newFrontController = nil;
PaMapViewController * vc = [[PaMapViewController alloc] init];
newFrontController = [[UINavigationController alloc] initWithRootViewController:vc];
SWRevealViewController *revealController = self.revealViewController;
[revealController pushFrontViewController:newFrontController animated:YES];
} andFailureBlock:^(AFHTTPRequestOperation *operation, NSError *error)
{
NSDictionary *dic = [error.userInfo objectForKey:@"JSONResponseSerializerWithDataKey"];
#ifdef DEBUG
NSLog(@"dic = %@", dic);
#endif
if ([[dic objectForKey:@"error_uri"] isEqual:@"phone"])
{
NSError *jsonError;
NSData *objectData = [[dic objectForKey:@"error_description"] dataUsingEncoding:NSUTF8StringEncoding];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData
options:NSJSONReadingMutableContainers
error:&jsonError];
[self loginFailed:json];
}
else
{
[self loginFailed:dic];
}
}];
}
else
{
//TODO: show proper message Test
NSLog(@"username or password is empty %@", kBaseURL);
}
}
- (void)showLoginProcess:(BOOL) show
{
[self.spinner setColor:[UIColor whiteColor]];
self.spinner.hidden = !show;
self.usernameBox.hidden = show;
self.passwordBox.hidden = show;
if (show)
{
[self.spinner startAnimating];
} else
{
[self.spinner stopAnimating];
}
}
爲什麼,,爲什麼不這樣做'''enabled'''? –
啓用/禁用是突出顯示按鈕的屬性。而用戶交互啓用設置則允許用戶與UI進行交互。例如,如果你寫btn.enable = false你的按鈕將看起來禁用,但你仍然可以點擊它。另一方面,如果你寫btn.userInteractionEnable = false,你不能點擊按鈕。 – iAnurag