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 回答