首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIAlertView不应调用popViewControllerAnimated

UIAlertView不应调用popViewControllerAnimated
EN

Stack Overflow用户
提问于 2014-07-15 19:52:31
回答 1查看 331关注 0票数 0

我有一个有一些UITextViews的视野。用户可以输入个人数据,姓名,电子邮件等。编辑完成后,用户点击右上角的“完成”,视图导航回以前的视图,如下所示:

代码语言:javascript
复制
- (void)save:(id)sender
{

    [self.view.window endEditing:YES];

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

}

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

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

警报视图的代码为

代码语言:javascript
复制
- (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能够再次做出响应呢?

EN

回答 1

Stack Overflow用户

发布于 2014-07-15 20:00:41

您将希望使用UIAlertViewDelegate。

下面是参考资料:

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

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

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

因此,当您实现它时,请检查按钮索引。基于索引,您可以控制逻辑中的下一步操作。

实例化UIAlertView时,请确保像这样设置代理:

代码语言:javascript
复制
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@""                                                         
                                                    message:NSLocalizedString(@"res_CurrentPasswordErrorAlert",nil)
                                                   delegate:self // this is the key!
                                          cancelButtonTitle:NSLocalizedString(@"res_OK",nil)
                                          otherButtonTitles:nil];
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24757553

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档