swift - Some cells bottom are being cut off using UICollectionViewCell and dequeueReusableCell -
i spent entire day trying figure out going on uicollectionview.
i’m trying implement feed news facebook, obscure reason i’m having weird behaviors reusing cells. i’ve read apple’s documentation related tons of time , tried diverses fixes.
i'm using firebase pull out data, when user scrolls down function asks more data , merges posts array, , calls collectionview.reloaddata()...
`
override func scrollviewdidenddragging(_ scrollview: uiscrollview, willdecelerate decelerate: bool) { // uitableview moves in 1 direction, y axis let currentcontentoffset = scrollview.contentoffset.y let maximumcontentoffset = scrollview.contentsize.height - scrollview.frame.size.height // set minimum distance bottom load more posts if maximumcontentoffset - currentcontentoffset <= 1000.0 { self.updatenewrecords(withoffset: self.currentoffset, findoffsetbyiteminarray: false) } }
a second function
override func collectionview(_ collectionview: uicollectionview, cellforitemat indexpath: indexpath) -> uicollectionviewcell { let post = posts[indexpath.item] let feedcell: feedcell feedcell = collectionview.dequeuereusablecell(withreuseidentifier: feedcelltype.withimage, for: indexpath) as! feedcell feedcell.post = post feedcell.delegate = self return feedcell }
because content dynamic need calculate estimated heigh...
func collectionview(_ collectionview: uicollectionview, layout collectionviewlayout: uicollectionviewlayout, sizeforitemat indexpath: indexpath) -> cgsize { let postitem = posts[indexpath.item] if let statustext = postitem.content { var knownverticalsize: cgfloat if postitem.featuredimageurl != nil { knownverticalsize = 311 } else { knownverticalsize = 212 } let estimatedtextstringsize = nsstring(string: statustext).boundingrect(with: cgsize(width: view.frame.width - 16, height: 1000), options: nsstringdrawingoptions.usesfontleading.union(nsstringdrawingoptions.useslinefragmentorigin), attributes: [nsfontattributename: uifont.systemfont(ofsize: 14)], context: nil) return cgsize(width: view.frame.width, height: estimatedtextstringsize.height + knownverticalsize + 60) } return cgsize(width: view.frame.width, height: 220) }
my cell created programmatically, in init call function create elements , set constraints. changeable height content takes rest of available height view. don't think problem on constraints. debugging can see elements there, height reserved reason doesn't completly display.
i'm calling prepareforreuse clean labels, image , textview. though have weirder error image... when 3 cells being showed on screen, when image of 3rd 1 loads replaces image of first one. have no clue why.
i'm stressed out. ask questions because searching can find solution. found many problems related mine, , tested solutions , nothing seems work.
i appreciate help.
check screens illustrating problem: after 2 posts correctly showed, bottom of 3rd 1 cut off the last post 6th: bottom cut off
edit
i believe found correlation between problem , init being called. have 6 posts , init called 4 times. problem layout in 2 posts only...
i'm kinda confused yet. @ first, thought reusable cell have init called once... can't figure why contraints have set every time.
i'm done today. tomorrow i'm going closer @ this.
Comments
Post a Comment