gpt4 book ai didi

ios - 我正在尝试为特定的 UIButton 调用 UIAlertView 方法,例如 UpdateEmail 或 ForgotPassword 但正确调用我正在使用此代码

转载 作者:行者123 更新时间:2023-11-29 12:11:00 25 4
gpt4 key购买 nike

我正在使用此代码来更新电子邮件地址和忘记密码,但是当我单击“忘记密码”按钮时,它们会出现问题,它可以正常工作,但是当我单击“更新电子邮件”按钮时,它无法正常工作,它会调用 UIAlert for 'ForgotPassword' button and I am trying to call"else if (self.ForgotPassword.tag == 1) -(Void)alertView 的一部分"当我按下 'UpdateEmail' UIButton 时。

//Forgot method for ForgotPassword

-(IBAction)ForgotPassword:(id)sender

{
UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:@"Forgot Password" message:@"Please enter your email id" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
}

//Method for Update Email Address

-(IBAction)UpdateEmail:(id)sender

{
if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Update Email"
message:@"Enter Your Email Address"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
}
else
{
UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:@"Please First Loginig"
message:@"Please First Loging"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
[myAlert1 show];
}
}

// Method for Alert View

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{

self.ForgotPassword.tag=0;
self.UpdateEmail.tag=1;

if (self.ForgotPassword.tag == 0){

if(buttonIndex ==1){

NSLog(@"ok button clicked in forgot password alert view");
NSString *femailId=[alertView textFieldAtIndex:0].text;

if ([femailId isEqualToString:@""]){

UIAlertView *display;

display=[[UIAlertView alloc] initWithTitle:@"Email" message:@"Please enter password for resetting password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];
[display show];
}else{

[PFUser requestPasswordResetForEmailInBackground:femailId block:^(BOOL succeeded, NSError *error){

UIAlertView *display;

if(succeeded){

display=[[UIAlertView alloc] initWithTitle:@"Password email" message:@"Please check your email for resetting the password" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles: nil];

}else{

display=[[UIAlertView alloc] initWithTitle:@"Email" message:@"Email doesn't exists in our database" delegate:nil cancelButtonTitle:@"Cancel" otherButtonTitles: nil];
}
[display show];
}];
}
}
}else if (self.ForgotPassword.tag == 1){

PFUser *user = [PFUser currentUser];
user[@"email"] = [alertView textFieldAtIndex:0].text;
[user saveInBackgroundWithBlock:^(BOOL succeeded, NSError *error){

if (succeeded){

UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:@"Email Upadated!"
message:@"your Email is Updated"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
[myAlert1 show];
//NSLog(@"Success");
}else{

UIAlertView *myAlert1 = [[UIAlertView alloc]
initWithTitle:@"Email is NOT Update"
message:@"Email is alredy registred"
delegate:nil
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
[myAlert1 show];
NSLog(@"Error");
}
}];
}

}

最佳答案

你需要给你的两个不同的 UIAlertView 标签,如下所示。

-(IBAction)ForgotPassword:(id)sender

{

UIAlertView * forgotPassword=[[UIAlertView alloc] initWithTitle:@"Forgot Password" message:@"Please enter your email id" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Ok", nil];

forgotPassword.alertViewStyle=UIAlertViewStylePlainTextInput;
[forgotPassword textFieldAtIndex:0].delegate=self;
[forgotPassword show];
forgotPassword.tag = 0; //// Here for forgot password
}

-(IBAction)UpdateEmail:(id)sender

{

if ([PFUser currentUser])
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Update Email"
message:@"Enter Your Email Address"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"Ok",nil];
alert.alertViewStyle = UIAlertViewStylePlainTextInput;
[alert show];
alert.tag =1; ///Here for email update
}
}

然后,在 -(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex 中,您可以检测点击了哪个 alertView 的按钮。

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
{
if(alertView.tag == 0) /// Because we assigned forgotPassword.tag = 0; above for forgotPassword
{

if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Forgot Password.

}
}
else if(alertView.tag ==1) /// Because we assigned alert.tag = 1; above for update email
{
if(buttonIndex == YOUR_DESIRED_BUTTON_INDEX)
{
///Your code for Update Email.

}
}
}

关于ios - 我正在尝试为特定的 UIButton 调用 UIAlertView 方法,例如 UpdateEmail 或 ForgotPassword 但正确调用我正在使用此代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33430861/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com