1

PFLogInViewControllerポップアップするデフォルトの動作とは異なる方法でエラーを表示したいのサブクラスを使用していますUIAlertView

を表示しないようにする方法があるかどうかは誰にもわかりUIAlertViewませんか? 私はすでに次の方法を使用していますUIAlertViewが、ログインに失敗した場合に表示されることを実際に回避することはできません。

- (BOOL)logInViewController:(PFLogInViewController *)logInController shouldBeginLogInWithUsername:(NSString *)username password:(NSString *)password
4

1 に答える 1

0

PFLogInViewControllerこの動作を変更するためのフックを提供しません。独自のカスタムPFLogInViewControllerサブクラスを作成し、ログインが失敗したときにアラート ビューを表示するメソッドをオーバーライドすることができます。

PFLogInViewController のコードはオープンソース化されているので、それによるとアラートビューを表示するメソッドは_loginDidFailWithError.

https://github.com/ParsePlatform/ParseUI-iOS/blob/master/ParseUI/Classes/LogInViewController/PFLogInViewController.m#L382-L390

- (void)_loginDidFailWithError:(NSError *)error {
    if (_delegateExistingMethods.didFailToLogIn) {
        [_delegate logInViewController:self didFailToLogInWithError:error];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:PFLogInFailureNotification object:self];

    NSString *title = NSLocalizedString(@"Login Error", @"Login error alert title in PFLogInViewController");
    [PFUIAlertView showAlertViewWithTitle:title error:error];
}

例えば以下のような場合、ログイン失敗時のアラート表示を非表示にできます。MYLogInViewControllerのサブクラスとして定義PFLogInViewController

@interface MYLogInViewController : PFLogInViewController

@end

@implementation MYLogInViewController

- (void)_loginDidFailWithError:(NSError *)error {
    if ([self.delegate respondsToSelector:@selector(logInViewController:didFailToLogInWithError:)]) {
        [self.delegate logInViewController:self didFailToLogInWithError:error];
    }
    [[NSNotificationCenter defaultCenter] postNotificationName:PFLogInFailureNotification object:self];
}

@end

代わりにそれを使用してくださいPFLogInViewController

MYLogInViewController *logInViewController = [[MYLogInViewController alloc] init];
logInViewController.delegate = self;
[self presentViewController:logInViewController animated:YES completion:nil];
于 2015-01-31T17:35:43.267 に答える