मैं एक आईओएस एप्लिकेशन विकसित कर रहा हूं जो सर्वर से पोस्ट को UICollectionView में लोड करता है। संग्रह दृश्य कक्ष में UIImageView शामिल है जो सेल के नीचे तय किया गया है।संग्रह दृश्य कक्ष छवियों को सही ढंग से लोड नहीं कर रहे हैं
जब भी मैं आवेदन और संग्रह दृश्य लोड शुरू, सभी छवियों को सही ढंग से, लेकिन पिछले छवि है, जो सही आयाम है के लिए लोड न करें। सभी कोशिकाओं को उसी तरह स्वरूपित किया जा रहा है।
मैं समाधान लेकिन कुछ भी की एक भीड़ अब तक काम किया है की कोशिश की है।
मुझे क्या संदेह है कि छवियां प्रत्येक सेल के UIImageView (इस मामले में अंतिम को छोड़कर) पर सेट होने से पहले लोडिंग समाप्त नहीं हुई हैं। यह हालांकि संभव प्रतीत नहीं होता है के रूप में कोशिकाओं एक सफल प्रतिक्रिया प्राप्त करने के बाद पुनः लोड कर रहे हैं ..
यह उस विशेष समारोह (Alamofire का प्रयोग करके) के लिए मेरे कोड
func getAllPosts(){
let url = "\(Constants.baseURL)/posts/"
let parameters = ["user_id": "\(userProfile!.getId())"]
Alamofire.request(.POST, url, parameters: parameters, encoding: .JSON)
.validate(contentType: ["application/json"])
.responseString { response in
switch response.result {
case .Success:
var postsArray = Array<[String: AnyObject]>()
do {
let json = try NSJSONSerialization.JSONObjectWithData(response.data!, options: NSJSONReadingOptions.MutableContainers)
for post in json as! [AnyObject] {
postsArray.append(post as! [String: AnyObject])
}
//invert array of posts so that latest load first!
postsArray = postsArray.reverse()
} catch {
}
//convert json to Post objects and reload the view
self.initialisePosts(postsArray)
self.collectionView?.reloadData()
case .Failure(let error):
print(error)
}
}
}
सभी मदद की सराहना की है।
संपादित करें: नीचे वर्तमान बाधाओं UIImageView पर
संपादित 2 हैं: का उपयोग करते हुए @ माइकल की सलाह मेरे पास है: यहाँ कोशिकाओं
override func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -> UICollectionViewCell {
// get a reference to our postcell with no image
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(reuseIdentifiers[0], forIndexPath: indexPath) as! PostCell
guard let _: Post? = posts[indexPath.row] else {
return cell
}
return configurePostCell(cell, post: posts[indexPath.row])!
}
func configurePostCell(cell: UICollectionViewCell, post: Post) -> PostCell?{
if let cell = cell as? PostCell {
cell.author.text = post.user_name
cell.date.text = formatter.stringFromDate(post.pub_date!)
cell.desc.text = post.desc
cell.layer.cornerRadius = 5 //set corner radius here
cell.advertImage.image = post.advert?.advert_image
return cell
}
return nil
}
अद्यतन फ़ॉर्मेट करने के लिए कोड है पाया गया कि सेल छवियां सही ढंग से लोड हो रही हैं ..
लेकिन है कि सेल ऊंचाई रहस्यमय तरीके से 50px द्वारा काटी जा रही है ..
स्टोरीबोर्ड संपादक सेल के आकार रन-टाइम में
सेल आकार
ऐसा लगता है लेकिन मुझे अभी तक कोई समाधान नहीं मिला है।
अद्यतन: बकाया पर दो घंटे शेष के साथ मैंने इसे @ माइकल को पुरस्कृत करने का निर्णय लिया है क्योंकि उनके जवाब ने मुझे मेरी समस्या की और जांच करने में मदद की, जो अभी भी चल रहा है।
कहाँ संग्रह देखने के लिए छवियों को स्थापित करने के लिए अपने कोड है? क्या आपने UIImageView के लिए ऊंचाई बाधा दी है? –
ओह हाँ क्षमा करें, मैं उस जानकारी को शामिल करने के लिए अब प्रश्न संपादित कर दूंगा। – Danoram
इसे मुख्य_क्यू –