2

私は iOS アプリのバックエンドとして Parse を使用しており、ログインおよびサインアップ タスクにもネイティブのPFLogInViewController&を使用しています。PFSignUpViewController

問題?

アプリ全体で UIAlertViews の外観をカスタマイズしましたが、Parse のネイティブ PFLogInViewController および PFSignUpViewController 実装で UIAlertViews への呼び出しがハードコードされていることがわかりました。このアラート ビューの例は、ユーザー名とパスワードの組み合わせが正しくないためにログインが失敗した場合です。

PFLogInViewController&をサブクラスPFSignUpViewController化し、独自のカスタム UIAlertView クラスを実装する方法を考えています。

編集 — アイデアはありますか?

4

2 に答える 2

1

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];

    NSString *title = NSLocalizedString(@"Login Error", @"Login error alert title in PFLogInViewController");
    //
    // Implement to display your custom alert view
    //
}

@end

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

MYLogInViewController *logInViewController = [[MYLogInViewController alloc] init];
logInViewController.delegate = self;
[self presentViewController:logInViewController animated:YES completion:nil];
于 2015-01-31T19:19:07.347 に答える
0

ここを参照してください: https://parse.com/tutorials/login-and-signup-viewsの「フル カスタマイズのサブクラス化」。

于 2013-03-20T22:35:56.943 に答える