私の仕事は、Alamofire経由でJSONを読み込むために、私の配列を埋めて、すぐにfunc collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
の中に入れて表示しますが、私の問題はあります。空の。私は私のようにcompletionHandlerでこの問題を解決することができると考えなぜcompletionHandlerブロックは応答しませんか?
:
後でfunc abcd(completion: (() -> Void)) {
let getMyProfileURL = "\(self.property.host)\(self.property.getMyProfile)"
Alamofire.request(.POST, getMyProfileURL, parameters: self.userParameters.profileParameteres, encoding: .JSON).responseJSON { response in
do {
let json = JSON(data: response.data!)
if json["user"].count > 0 {
self.profileDetails.append(ProfileDetailsModel(json: json["user"]))
}
}
}
}
、私はそれを呼び出す:
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -> UICollectionReusableView {
self.abcd {
print("SUCCESS")
print(self.profileDetails)
}
}
が、それは私のcompletionHandler
コードprints
を印刷しません。どうして?問題は何ですか?どのように修正できますか?
P.Sあなたが私の仕事のためのより良い解決策を提供できるなら、それは素晴らしいことでしょう!
は配列を初期化します。 – sourav
コレクションビューをリロードする必要があります。非同期データ要求が完了したら、 –
関数 'abcd'で補完ブロックを呼び出さなかったので、何も印刷されません。 – TangZijian