i'm developing ios application loads posts server uicollectionview. collection view cell includes uiimageview fixed bottom of cell.
whenever start application , collection view loads, images not load correctly last image, correct dimensions. cells being formatted same way.
i have tried multitude of solutions nothing far has worked.
what suspect happening images have not finished loading before being set uiimageview of each cell (except last 1 in case). doesn't seem possible though cells reloaded after getting successful response..
this code particular function (using 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]>() { let json = try nsjsonserialization.jsonobjectwithdata(response.data!, options: nsjsonreadingoptions.mutablecontainers) post in json as! [anyobject] { postsarray.append(post as! [string: anyobject]) } //invert array of posts latest load first! postsarray = postsarray.reverse() } catch { } //convert json post objects , reload view self.initialiseposts(postsarray) self.collectionview?.reloaddata() case .failure(let error): print(error) } } }
all appreciated.
edit: below current constraints on uiimageview
edit 2: here code formatting cells
override func collectionview(collectionview: uicollectionview, cellforitematindexpath indexpath: nsindexpath) -> uicollectionviewcell { // reference our postcell 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 }
update: using @michael's advice have found cell images are loading correctly..
but cell height being mysteriously cropped 50px..
storyboard editor cell size
cell size @ run-time
this seems issue have not found solution yet.
update: 2 hours left on bounty have decided award @michael because answer helped me further investigation of issue, still ongoing.
firstly, use debug view hierarchy button check anomalies in table cells @ runtime.
then breakpoint on cell creation , inspect uiimage set cell , make sure size right. if assign image downloaded local variable can quicklook too, see if looks right.
then, if seems sensible, check auto-layout code robust.
check removing downloading of images situation. this:
- remove setting of image @ all, set image background uicolor.red or , check layout nicely little more normal uiviews.
- embed image in app bundle png , set instead of downloaded image. again, @ how renders.
- try different sizes image in app bundle , check again (if relevant - maybe images same size anyway)
if looks good, know it's around download or layout of server images.
Comments
Post a Comment