ios - UIAlertView 处理文本字段

标签 ios objective-c alertview

我想做一个简单的 alertView 并询问电话号码...

   UIAlertView *message = [[UIAlertView alloc] initWithTitle:@"What is your phone number?"
                                                      message:nil
                                                     delegate:self
                                            cancelButtonTitle:@"Cancel"
                                            otherButtonTitles:@"Continue", nil];

    message.alertViewStyle = UIAlertViewStylePlainTextInput;
    UITextField* answerField = [message textFieldAtIndex:0];
    answerField.keyboardType = UIKeyboardTypeNumberPad;
    answerField.placeholder = @"+43 ...";

    [message show];

我必须在这里输入什么来检查数字(如 Mysql 等)

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

UITextField *textField = [alertView textFieldAtIndex:0];

    ?????????
    // Something like  if (textField == "090012345678") -> NSLog(@"WOW"); ...

   }

最佳答案

如果您不知道如何比较两个字符串是否相同,那么我建议您查找一些有关 Objective-C 的基础教程。

if ([textField.text isEqualToString:@"090012345678"]) {
    NSLog(@"WOW");
}

关于ios - UIAlertView 处理文本字段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18676988/

相关文章:

objective-c - 由于文本标签而导致 UICollectionView 滚动不稳定

ios - 带有 UITextField 的 UIAlertView - 使用 NSUserDefaults 保存

iphone - 如何在iPhone中的UIAlertView中添加UITableView?

ios - 为什么 -[UIColor setFill] 在不引用绘图上下文的情况下工作?

objective-c - BOOL 与 Swift 4.1 中的 Bool 不兼容

iphone - 从 View 中删除 modalViewController 吗?

ios - 从 Objective-C 中的另一个类呈现 "Controller"

iphone - 我可以确定用户是否拒绝访问照片吗?

ios - 如何检测 iOS 设备上的耳机(扬声器)可用性?