Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/120.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 动态选择UIPicker的行_Ios_Arrays_Swift - Fatal编程技术网

Ios 动态选择UIPicker的行

Ios 动态选择UIPicker的行,ios,arrays,swift,Ios,Arrays,Swift,我对以下代码有一个问题:UserLoad数组包含一系列带有用户名字段的用户,我想根据用户名选择uipicker行, 下面的代码找不到数组中以else结尾的文本 func selectPicker(withText text: String) { print("Testo: \(text)") if let index = self.UserLoad.firstIndex(where: { $0.Username == text }) { p

我对以下代码有一个问题:UserLoad数组包含一系列带有用户名字段的用户,我想根据用户名选择uipicker行, 下面的代码找不到数组中以else结尾的文本

func selectPicker(withText text: String) {
        print("Testo: \(text)")
        if let index = self.UserLoad.firstIndex(where: { $0.Username == text }) {
            print("Indice di riga: \(index)")
            RisorseUmaneUIPicker.selectRow(index, inComponent: 0, animated: true)
        }
        else {
            print("text not found")
        }
    }

您可以尝试使用
小写搜索

let sub = text.lowercased() 
if let index = self.userLoad.firstIndex(where: { $0.username.lowercased() == sub } {}

如果不起作用,则数组不包含该用户

以小写字母开头的属性名