0

こんにちは、セグエの準備メソッドを使用してセグエを実行しようとしています。この質問に従っていましたが、サインアップを成功させることができませんでした。サインアップ ボタンをクリックすると、ユーザーが登録され、そこで停止します。セグエをView Controllerから(ボタン自体からではなく)モーダルに接続したので、問題はありません。私の送信ビューは、テキスト フィールドと完了ボタンを備えた通常のビューであり、受信ビューは、行にラベル (nameLabel と呼ばれる) が付いた静的なテーブル ビューです。

2つの質問

1.セグエメソッドの準備に何が欠けていますか? (また、パースをバックエンドとして使用しているため、PFLogInSuccessNotification がどこから来るのか)

  1. また、ユーザーのユーザー名をプロファイル ビューに渡すにはどうすればよいですか?

お時間を割いていただき、ありがとうございました。

**my segue method**

 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"can you see this");
    if ([segue.identifier isEqualToString:@"SegueTOprofile"])
    {
        if (PFLogInSuccessNotification) {
       profileTableViewController *myProfileView = (profileTableViewController *)[segue destinationViewController];

            PFUser *user =[PFUser user];
            user.username = myProfileView.nameLabel.text;
                   //   NSLog(@"%@",myProfileView.nameLabel.text);
    }

    }
    [self performSegueWithIdentifier:@"SegueTOprofile" sender:self];


}

**これは私のサインアップ ビューです ** .h

#import <UIKit/UIKit.h>
extern NSString *const PFSignUpSuccessNotification;
extern NSString *const PFSignUpFailureNotification;

@interface SignUpViewController : UIViewController<UITextFieldDelegate>


@property (strong, nonatomic) IBOutlet UITextField *emailNameField;
@property (strong, nonatomic) IBOutlet UITextField *passwordField;
@property (strong, nonatomic) IBOutlet UIButton *signupButton;
- (IBAction)SignUp:(id)sender;
@property (strong, nonatomic) IBOutlet UITextField *repeatPasswordField;
@property (strong, nonatomic) IBOutlet UIBarButtonItem *BackButton;
@property (strong, nonatomic) IBOutlet UITextField *usernameField;

.m

#import "SignUpViewController.h"
#import "profileTableViewController.h"
#import <Parse/Parse.h>
#import "ActivityView.h"
#import "TabBarCustomClassViewController.h"
@interface SignUpViewController ()

-(void)processFieldEntries;
- (void)textInputChanged:(NSNotification *)note;
- (BOOL)shouldEnableDoneButton;

@end

@implementation SignUpViewController
@synthesize signupButton = _signupButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}


- (void)viewDidLoad
{
    [super viewDidLoad];


    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_usernameField];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_emailNameField];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_passwordField];

    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(textInputChanged:) name:UITextFieldTextDidChangeNotification object:_repeatPasswordField];


}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    if (textField == _usernameField) {
        [_usernameField becomeFirstResponder];
    }
    if (textField == _emailNameField) {
  [_emailNameField becomeFirstResponder];}
    if (textField == _passwordField) {
        [_passwordField becomeFirstResponder];
    }
    if (textField == _repeatPasswordField) {
        [_repeatPasswordField becomeFirstResponder];
    }

    return  YES;
}

-(BOOL)shouldEnableDoneButton
{
    BOOL enableDoneButton = NO;
    if (_emailNameField.text != nil && _passwordField.text != nil && _repeatPasswordField != nil && _usernameField.text != nil) {
        enableDoneButton = YES;
    }
    return enableDoneButton;
}
/*
 // Using segue --> Send the current selected profile to "ProfileView"
 ProfileViewController *aProfileView = (ProfileViewController *)[segue destinationViewController];
 aProfileView.currentProfile = selectedProfile; */


 -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    NSLog(@"can you see this");
    if ([segue.identifier isEqualToString:@"SegueTOprofile"])
    {
        if (PFLogInSuccessNotification) {
       profileTableViewController *myProfileView = (profileTableViewController *)[segue destinationViewController];

            PFUser *user =[PFUser user];
            user.username = myProfileView.nameLabel.text;
                   //   NSLog(@"%@",myProfileView.nameLabel.text);
    }

    }
    [self performSegueWithIdentifier:@"SegueTOprofile" sender:self];


}



-(void)textInputChanged:(NSNotification *)note
{
    _signupButton.enabled = [self shouldEnableDoneButton];

}
- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (IBAction)SignUp:(id)sender {
    [_usernameField resignFirstResponder];
    [_emailNameField resignFirstResponder];
    [_passwordField resignFirstResponder];
    [_repeatPasswordField resignFirstResponder];
    [self processFieldEntries];
}
-(void)processFieldEntries
{
    // Check that we have a non-zero username and passwords.
    // Compare password and passwordAgain for equality
    // Throw up a dialog that tells them what they did wrong if they did it wrong.
    NSString *email = _emailNameField.text;
    NSString *passwordd = _passwordField.text;
    NSString *passwordAgainn = _repeatPasswordField.text;
    NSString *username = _usernameField.text;

    NSString *errorText = @"Please ";
    NSString *usernameBlankText = @"enter a username";
    NSString *passwordBlankText = @"enter a password";
    NSString *joinText = @", and ";
    NSString *passwordMismatchText = @"enter the same password twice";


    BOOL textError = NO;

    if (email.length == 0 || passwordd.length == 0 || passwordAgainn.length == 0) {
        textError = YES;

        // Set up the keyboard for the first field missing input:
        if (passwordAgainn.length == 0) {
            [_repeatPasswordField becomeFirstResponder];
        }
        if (passwordd.length == 0) {
            [_passwordField becomeFirstResponder];
        }
        if (username.length == 0) {
            [_usernameField becomeFirstResponder];
        }

        if (email.length == 0) {
            errorText = [errorText stringByAppendingString:usernameBlankText];
        }

        if (passwordd.length == 0 || passwordAgainn.length == 0) {
            if (email.length == 0) { // We need some joining text in the error:
                errorText = [errorText stringByAppendingString:joinText];
            }
            errorText = [errorText stringByAppendingString:passwordBlankText];
        }
    } else if ([passwordd compare:passwordAgainn] != NSOrderedSame) {
        // We have non-zero strings.
        // Check for equal password strings.
        if (_signupButton.enabled == YES) {
            textError = YES;
            errorText = [errorText stringByAppendingString:passwordMismatchText];

        }
    }
    if (textError) {
        UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:errorText message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
        [alertView show];
        return;
    }

    // Everything looks good; try to log in.
    // Disable the done button for now.
    _signupButton.enabled = NO;
    ActivityView *activityView = [[ActivityView alloc] initWithFrame:CGRectMake(0.f, 0.f, self.view.frame.size.width, self.view.frame.size.height)];

    UILabel *label = activityView.label;
    label.text = @"Signing You Up";
    label.font = [UIFont boldSystemFontOfSize:20.f];
    [activityView.activityIndicator startAnimating];
    [activityView layoutSubviews];

    [self.view addSubview:activityView];

    // Call into an object somewhere that has code for setting up a user.
    // The app delegate cares about this, but so do a lot of other objects.
    // For now, do this inline.

    PFUser *user = [PFUser user];

    user.email = email;
    user.password = passwordAgainn;
    user.username = username;
    [user signUpInBackgroundWithBlock:^(BOOL succeeded, NSError *error) {
        if (error) {
            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:[[error userInfo] objectForKey:@"error"] message:nil delegate:self cancelButtonTitle:nil otherButtonTitles:@"Ok", nil];
            [alertView show];
            _signupButton.enabled = [self shouldEnableDoneButton];
            [activityView.activityIndicator stopAnimating];
            [activityView removeFromSuperview];
            // Bring the keyboard back up, because they'll probably need to change something.
            [_emailNameField becomeFirstResponder];

            return;
        }

        // Success!
        [activityView.activityIndicator stopAnimating];
        [activityView removeFromSuperview];




}];
}
@end
4

2 に答える 2

2

prepareForSegue はセグエを実行しません。これは、宛先ビュー コントローラーにデータを渡すことができる場所です。(ボタンではなく) コントローラーからセグエを接続した場合は、手動で performSegueWithIdentifier:sender を使用してセグエを呼び出す必要があります。

この行でそれをトリガーするつもりなら:

[self shouldPerformSegueWithIdentifier:@"SegueTOprofile" sender:self];

それは次のようになります。

[self performSegueWithIdentifier:@"SegueTOprofile" sender:self];

コードで2つの異なるセグエ識別子を使用しているため、それが意図したものかどうかはわかりません。

于 2013-09-11T04:26:08.337 に答える
0

バックエンドとして parse.com を使用してログイン プロセスを実装する方法のクリーンな例を次に示します。これは最終的に必要なものだったので、ここにも投稿しています。

https://github.com/gfosco/AccountDemo1

于 2013-09-13T00:56:56.597 に答える