gpt4 book ai didi

ios - UIAlertView 不应调用 popViewControllerAnimated

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

我有一个带有一些 UITextView 的 View 。用户可以输入个人数据、姓名、姓氏、电子邮件等。编辑完成后,用户点击右上角的“完成”, View 像这样导航回上一个 View :

- (void)save:(id)sender
{

[self.view.window endEditing:YES];

if (self.data ...)
{
[self updateUser];
[self.navigationController popViewControllerAnimated:YES];
}

}

客户要求在某些字段中添加一些验证,例如电子邮件。验证后,UIAlertView 通知数据输入无效,因此不会存储数据。我的问题是 AlertView 的“确定”按钮调用“保存”方法,并且调用 navigationController 并调用 popViewControllertAnimated。

这里的问题是,我想在 UIAlertView 之后避免自动导航到前一个 View (通过 popViewControllerAnimated),更准确地说,我想留在我的编辑 View 上并键入一个新的有效电子邮件。

警报 View 的代码是

- (void)alertInvalid {

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"" message:NSLocalizedString(@"res_CurrentPasswordErrorAlert",nil)
delegate:nil cancelButtonTitle: NSLocalizedString(@"res_OK",nil) otherButtonTitles:nil];

[alertView show];

}

通过 -(BOOL)textFieldShouldEndEditing:(UITextField *)textField 方法调用。那么,在警报消息出现后,如何修改代码以使当前 UITextView 再次响应?

最佳答案

您将需要使用 UIAlertViewDelegate。

这里是引用:

https://developer.apple.com/library/ios/documentation/uikit/reference/UIAlertViewDelegate_Protocol/UIAlertViewDelegate/UIAlertViewDelegate.html

但底线是您将实现此方法:

  • (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex

所以当你实现它的时候,检查按钮索引。根据索引,您可以控制逻辑中接下来发生的事情。

当你实例化你的 UIAlertView 时,一定要像这样设置委托(delegate):

UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""                                                         
message:NSLocalizedString(@"res_CurrentPasswordErrorAlert",nil)
delegate:self // this is the key!
cancelButtonTitle:NSLocalizedString(@"res_OK",nil)
otherButtonTitles:nil];

关于ios - UIAlertView 不应调用 popViewControllerAnimated,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24757553/

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