0
MLPAutoCompleteTextFieldデリゲートメソッドでネットワーク操作後に配列を返す必要があります。これに関する提案は非常に役に立ちます。代わりにコールバッククロージャの成功と失敗のデリゲートメソッドを持つiOS:ネットワーク操作後に関数から値を返します。
func autoCompleteTextField(textField: MLPAutoCompleteTextField!, possibleCompletionsForString string: String!, completionHandler handler: (([AnyObject]!) -> Void)!) {
//Perform network operation. Success and Failure conditions are handled below by implementing the protocol
service.getData(string)
//Have to return this only after network operation is completed either success or failure
handler(autoCompleteSuggestionsArray)
}
//Handle successful network call
func handleSuccess(model: Model) {
autoCompleteSuggestionsArray.removeAll()
for item in model.items {
if let itemName = item.name {
autoCompleteSuggestionsArray.append(itemName)
}
}
}
//Handle failed network call
//
func handleErrorWithMessage(message: String) {
autoCompleteSuggestionsArray.removeAll()
}
あなたは私の一日行われ...ありがとう!私はservice.getData(string:String、success:SuccessClosure、failure:FailureClosure)を使用できません。これは、多くのコントローラで使用されているグローバルサービスであり、同じことを続ける必要があるためです。ハンドラを変数に保存し、それを渡す際のあなたの提案。 –