如何对所有值的文本框扫描在单独的迅速数组? [英] How to have a textfield scan for all values in an array individually in swift?

查看:127
本文介绍了如何对所有值的文本框扫描在单独的迅速数组?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的同类迅速和编程语言,我真的一直在一个字符串数组各自具有一个文本框的外观所有值挣扎。所以
这里是我的code:

I am relatively new to swift and programming languages of its kind, and I have really been struggling with having a textfield look for ALL values individually in a string array. So here's my code:

var greetingArray = ["Hi", "hi", "hello", "Hello", "hey", "Hey", "sup", "Sup", "What's up", "what's up"]

以上是数组,以下是文本字段的行动。

Above is the array, and below is the textfield's action.

@IBAction func textUltraAction(textout: UITextField) { 
}

如果在textout.text是greetingArray的问候语中的任何一个(但不是所有的人都统称),我要完成的动作。例如,如果SUP或喜,在文本字段便被输入,我想完成的动作。我不想必须手动输入了:

If the "textout.text" is any one of the greetings in greetingArray (but not all of them collectively), I want to complete the action. For example, if "sup" or "hi" is inputed in the textfield, i want to complete the action. I do not want to manually have to type out:

greetinArray[0], greetinArray[1], greetinArray[2], etc...

在此先感谢您的帮助任何人都可以给我!

Thanks in advance for any help anyone can give me!

推荐答案

试试这个:

if contains(greetingArray, yourTextField.text) {
    //Here you got it
}

希望这有助于..:)

Hope this helps.. :)

这篇关于如何对所有值的文本框扫描在单独的迅速数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆