gpt4 book ai didi

ios - 从 ios 中的另一个弹出按钮执行弹出窗口

转载 作者:行者123 更新时间:2023-11-28 21:57:45 24 4
gpt4 key购买 nike

我是 IOS 新手。当我点击以下登录按钮时:

enter image description here

我正在使用此代码生成弹出窗口:

- (UIView *)createLoginView
{
UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 130)];

UITextField *email = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 280, 50)];
email.tag=420;
email.layer.cornerRadius = 5;
[email setTag:99];
[email setTextAlignment:NSTextAlignmentCenter];
[email setKeyboardType:UIKeyboardTypeEmailAddress];
[email setPlaceholder:@"Email"];
[email setBackgroundColor:[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0]];
[email setReturnKeyType:UIReturnKeyNext];
[email setAutocorrectionType:UITextAutocorrectionTypeNo];

UITextField *pass = [[UITextField alloc] initWithFrame:CGRectMake(10, 70, 280, 50)];
pass.layer.cornerRadius = 5;
[pass setTag:100];
[pass setTextAlignment:NSTextAlignmentCenter];
[pass setSecureTextEntry:YES];
[pass setPlaceholder:@"Password"];
[pass setBackgroundColor:[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0]];
[pass setReturnKeyType:UIReturnKeyGo];

[alertView addSubview:email];
[alertView addSubview:pass];
return alertView;
}

enter image description here

登录弹出窗口工作正常,但当我单击“忘记?”时弹出窗口的按钮,忘记密码弹出窗口不会显示。这是忘记密码弹出窗口的代码。

- (UIView *)createForgotPasswordView
{
UIView *alertView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 300, 130)];

UITextField *email = [[UITextField alloc] initWithFrame:CGRectMake(10, 10, 280, 50)];

email.layer.cornerRadius = 5;
[email setTag:22];
[email setTextAlignment:NSTextAlignmentCenter];
[email setKeyboardType:UIKeyboardTypeEmailAddress];
[email setPlaceholder:@"Email"];
[email setBackgroundColor:[UIColor colorWithRed:243/255.0 green:243/255.0 blue:243/255.0 alpha:1.0]];
[email setReturnKeyType:UIReturnKeyNext];
[email setAutocorrectionType:UITextAutocorrectionTypeNo];

[alertView addSubview:email];
return alertView;
}

我正在使用它:

- (IBAction)LogInClick:(UIButton *)sender {
IOS7AlertView *applyMsg = [[IOS7AlertView alloc] init];
[applyMsg setContainerView:[self createLoginView]];

[applyMsg setButtonTitles:[NSMutableArray arrayWithObjects:@"Forgot?", @"Login", nil]];


[applyMsg setOnButtonTouchUpInside:^(IOS7AlertView *alertView, int buttonIndex) {

if(buttonIndex==0)
{

[alertView close];

NSLog(@"Forgot Section");

IOS7AlertView *applyPop = [[IOS7AlertView alloc] init];
[applyPop setParentView:[self createForgotPasswordView]];


[applyPop setButtonTitles:[NSMutableArray arrayWithObjects:@"Next", @"Cancel", nil]];

}
}];

但问题是下一个弹窗不显示?问题是什么?请帮忙。

最佳答案

UIalertview 层次结构已经有电子邮件和密码选项。

试试这个,这是原生的

 - (IBAction)LogInClick:(UIButton *)sender {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Login"
message:nil
delegate:self
cancelButtonTitle:@"Signup"
otherButtonTitles:@"Login",@"Forgot password", nil];

alert.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;

[[alert textFieldAtIndex:0]setKeyboardType:UIKeyboardTypeEmailAddress];
[[alert textFieldAtIndex:0]setPlaceholder:@"Email address"];
[[alert textFieldAtIndex:1]setPlaceholder:@"Password"];
alert.tag=10;
[alert show];
}

alert view delegate方法是

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

if (alertView.tag==65)
{
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle:@"Login"
message:nil
delegate:self
cancelButtonTitle:@"Signup"
otherButtonTitles:@"Login",@"Forgot password", nil];

alert.alertViewStyle=UIAlertViewStyleLoginAndPasswordInput;

[[alert textFieldAtIndex:0]setKeyboardType:UIKeyboardTypeEmailAddress];
[[alert textFieldAtIndex:0]setPlaceholder:@"Email address"];
[[alert textFieldAtIndex:1]setPlaceholder:@"Password"];
alert.tag=10;
[alert show];
}


if (alertView.tag==10)
{
if (buttonIndex == 0) {

NSLog(@"signup");
//Navigate to Signup page



}
else if (buttonIndex == 2) {
NSLog(@"Forgot password");

// //Navigate to Forgot password page
}
else if (buttonIndex == 1) {

NSLog(@"YES");

NSString *usernameInput=[alertView textFieldAtIndex:0].text;

NSString *passwordInput=[alertView textFieldAtIndex:1].text;

//pass the email id , password

NSLog(@"1 %@", usernameInput);
NSLog(@"2 %@", passwordInput);

NSString *emailReg = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailReg];


// COMMENT: check if input information is valid or not
if([usernameInput isEqualToString:@""])
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert!!!" message:@"You must fill in Email address" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alert.tag=65;
[alert show];


}
else if([emailTest evaluateWithObject:usernameInput] == NO)
{

UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert!!" message:@"Please Enter Valid Email Address." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
alert.tag=65;
[alert show];

}
else if([passwordInput isEqualToString:@""])
{
UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"Alert!!!" message:@"You must fill in Password" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
alert.tag=65;
[alert show];


}
else
{
//pass teh data to server or login process
}

}
}

关于ios - 从 ios 中的另一个弹出按钮执行弹出窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25930024/

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