iphone - 当两个文本字段都是一些文本时如何显示警报

标签 iphone ios uitextfield

<分区>


想改进这个问题吗? 通过 editing this post 添加细节并澄清问题.

已关闭 8 年前

我有两个 UITextField。我想检查 UITextField,如果两个 UITextField 是一些文本显示警报,或者如果只有一个 UITextField 有一些文本,则继续。

最佳答案

您可以使用UITextFieldDelegate的两个委托(delegate)函数

-(BOOL) textFieldShouldReturn:(UITextField *)textField
{
  [textField resignFirstResponder];
   return YES;
}

-(void)textFieldDidEndEditing:(UITextField *)textField
{
if ([self.textField1.text isEqualToString:self.textField2.text])
{
    UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Alert"
                                                    message:@"text field have same text"
                                                   delegate:nil
                                          cancelButtonTitle:@"Cancel"
                                          otherButtonTitles:nil];

    [alert show];
}
}

关于iphone - 当两个文本字段都是一些文本时如何显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18372329/

上一篇:ios - 为什么在ios中废弃的内存不被视为泄漏内存

下一篇:iphone - 我们可以先显示第二部分吗???

相关文章:

iphone - XCode 4.5 iOS 6.0 模拟器和旋转问题

ios - 无法将类型 ‘NSNull’ (0×106a4f520) 的值转换为 ‘NSDictionary’

iphone - 将 ivars 委托(delegate)为指针

iphone - 在 .htaccess/apache 中检测 iPhone 浏览器并重定向到 iPhone 站点

iphone - UITableViewCell accessoryType 已设置,但 accessoryView 为 nil。如何设置 accessoryView backgroundColor?

ios - 如何在 UITextField leftView 图像上获得左填充?

ios - 在 UITextField 操作中将 UITextField 字符串转换为 Double

ios - 如果 TextField 为空,则禁用按钮

iphone - SQLite 的删除和写入,使用 JSON 数据同步 MySQL 中的远程表

iphone - animateWithDuration 期间旋转的当前值