在我的get调用中,我收到了一些值,并附加了var nameData = [String]()
数组。 nameData数组值未显示外部语句。请检查我的以下代码
// Global Declarions
var nameData = [String]()
// GET Call values append
if let content = result["contacts"] as? [[String:AnyObject]] {
for category in content {
self.nameData.append(category["name"] as! String)
}
print(self.nameData) // here I am getting
}
}
self.addDropDown()
print(self.nameData) // Empty array showing
现在,下面是我的下拉代码,在这里我想分配nameData
数组
func addDropDown(){
print(self.nameData) // Empty array showing why???
// For Top textField
let dropDownTop = VPAutoComplete()
dropDownTop.dataSource = self.nameData -->// Here I need to assign nameData values if i do its showing empty values.
dropDownTop.onTextField = emailTF
dropDownTop.onView = self.view
dropDownTop.show { (str, index) in
print("string : \(str) and Index : \(index)")
self.emailTF.text = str
}
}
答案 0 :(得分:0)
尝试一下:
if let content = result["contacts"] as? [[String:AnyObject]] {
for category in content {
self.nameData.append(category["name"] as! String)
}
DispatchQueue.main.async { self.addDropDown() }
}
}
在填充nameData
数组后立即添加下拉列表。