ios - 自定义警报 View 的验证

标签 ios objective-c ios7 uiviewcontroller uialertview

我已将自定义 View 添加到警报 View 。

MyViewController *myViewController = [self.storyboard instantiateViewControllerWithIdentifier: @"MyView"];
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:nil message:nil delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:@"Submit", nil];                                                                                                           
[alertView setValue: myViewController.view  forKey:@"accessoryView"];              
[alertView show];

myViewController.view 中有一些文本字段。警报 View 有两个按钮“提交”和“取消”。

enter image description here

点击“提交”按钮后,我需要验证文本字段中的输入。如果输入无效,我不想解除警报。例如。如果电子邮件无效,我将显示另一个警告“电子邮件无效”。我该如何实现?到目前为止,我尝试了以下操作:

1) 在以下方法中编写验证逻辑:

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

但是执行此方法后警报 View 消失。

2) 子类化 UIAlertView。我试图在子类 UIAlertView 中覆盖以下方法:

- (void)dismissWithClickedButtonIndex:(NSInteger)buttonIndex animated:(BOOL)animated

虽然我点击警报 View 上的任何按钮,但不会调用此方法。苹果说,

The UIAlertView class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified.

我今天花了很多时间来解决这个问题,但没有运气..!!请帮我。

最佳答案

我的建议是用其他东西替换 UIAlertViewTTAlertViewSDCAlertView两者都在积极开发中,应该允许您以任何需要的方式灵活地对 View 进行子类化和/或皮肤处理。

关于ios - 自定义警报 View 的验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23110177/

相关文章:

ios - 如何正确使用 UINavigationController

ios - 在 cellForRowAtIndexPath 循环中获取 UIView 类型的 subview

ios - 根据键的值从 NSDictionary 的 NSMutableArray 中删除重复项

ios - Xcode 崩溃日志未出现

ios - 为 arm64 和 32 位架构编译时的基础类型

ios - subview 中的 exclusiveTouch 添加到 UITableViewCell

objective-c - 如何将值数组传递给 SudzC 生成的 Web 服务类?

objective-c - NSInputStream 不调用委托(delegate)(流 :handleEvent:)

ios - Cocos2D/iOS7 : continuously increasing memory usage for boilerplate code

ios - 如何将原始数据发送到 API