Я хочу отобразить индикатор активности вместо моего права UIBarButtonItem, пока мое приложение проверяет аутентификацию пользователей.Индикатор активности активности на месте входа в систему сразу же после нажатия на пользователя
Что происходит в настоящее время, пользователь нажимает кнопку входа в систему, тогда пользовательский интерфейс приостанавливается и ждет возврата веб-звонка. Было рекомендовано, что я использую очередь отправки для запуска этого в другом потоке, но я не уверен, как совместить эти два фрагмента кода:
Отправка очереди:
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(queue,^{
//show your indicator button
dispatch_async(dispatch_get_main_queue(),^{
//stop indicator when user has logged in
});
});
Войти Method :
- (void) loginAction{
UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc]
initWithFrame:CGRectMake(0, 0, 20, 20)];
[activityIndicator startAnimating];
UIBarButtonItem *activityItem = [[UIBarButtonItem alloc]
initWithCustomView:activityIndicator];
self.navigationItem.rightBarButtonItem = activityItem;
if ([userNameTextField.text isEqualToString:@""] || [passwordTextField.text
isEqualToString:@""]) {
UIBarButtonItem *btnGo = [[UIBarButtonItem alloc] initWithTitle:@"Login"
style:UIBarButtonItemStyleBordered target:self action:@selector(loginAction)];
self.navigationItem.rightBarButtonItem = btnGo;
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor colorWithRed:44.0/255.0
green:160.0/255.0 blue:65.0/255.0 alpha:1.0]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Login" message:@""
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
if (loginSuccess== true) {
//continue
}
}else
{
UIBarButtonItem *btnGo = [[UIBarButtonItem alloc] initWithTitle:@"Login"
style:UIBarButtonItemStyleBordered target:self action:@selector(loginAction)];
self.navigationItem.rightBarButtonItem = btnGo;
[self.navigationItem.rightBarButtonItem setTintColor:[UIColor colorWithRed:44.0/255.0
green:160.0/255.0 blue:65.0/255.0 alpha:1.0]];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Invalid Login" message:@""
delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
return;
}
}
Где бы я помещаю что? in viewDidLoad? – Brandon
Вы размещаете его там, где хотите показать свою кнопку индикатора, поэтому goog place будет viewWillAppear. – edzio27
Привет, я обновил свой вопрос. У меня возникли проблемы с этим. Есть ли указатели? – Brandon