this first time dealing ios development. i'm creating app uses custom uitableviewcell display information retrieved core data. im having issue imageview displays color disappears randomly when cell inserted table. if image view disappear, closing app , restarting fix problem.
right after inserting table: pic after force closing app , restarting: pic
any advice on problem appreciated.
here of relevant code. im using nsfetchedresultscontroller if helps.
override func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> customtableviewcell { let cell = self.tableview.dequeuereusablecellwithidentifier("cell") as! customtableviewcell let object = self.fetchedresultscontroller.objectatindexpath(indexpath) as! nsmanagedobject self.configurecell(cell, withobject: object) return cell } func configurecell(cell: customtableviewcell, withobject object: nsmanagedobject) { let imagedata: nsdata = object.valueforkey("image") as! nsdata let colorimageblank: uiimage = uiimage(named: "blank.png")! let picture: uiimage = uiimage(data: imagedata)! let date: nsdate let dateformatter = nsdateformatter() dateformatter.locale = nslocale.currentlocale() cell.cellimage.image = picture let colorstring = object.valueforkey("color")!.description var color: uicolor = uicolor() if colorstring == "blue" { color = uicolor.bluecolor() } else if colorstring == "red" { color = uicolor.redcolor() } else if colorstring == "green" { color = uicolor.greencolor() } else if colorstring == "yellow" { color = uicolor.yellowcolor() } else if colorstring == "orange" { color = uicolor.orangecolor() } else if colorstring == "purple" { color = uicolor.purplecolor() } cell.colorimage.image = colorimageblank cell.colorimage.backgroundcolor = color cell.colorimage.layer.cornerradius = 5.0 cell.cellimage.layer.borderwidth = 2 cell.cellimage.layer.bordercolor = color.cgcolor cell.cellimage.layer.cornerradius = 5.0 cell.locationnamelabel.text = object.valueforkey("name")!.description cell.locationnamelabel.font = uifont.boldsystemfontofsize(14.0) cell.locationnamelabel.linebreakmode = nslinebreakmode.bytruncatingtail cell.categorylabel.text = object.valueforkey("category")!.description cell.categorylabel.font = uifont.italicsystemfontofsize(12.0) cell.categorylabel.linebreakmode = nslinebreakmode.bytruncatingtail date = object.valueforkey("date")! as! nsdate dateformatter.datestyle = nsdateformatterstyle.shortstyle cell.datelabel.text = dateformatter.stringfromdate(date) cell.descriptionlabel.text = object.valueforkey("descript")!.description cell.descriptionlabel.linebreakmode = nslinebreakmode.bytruncatingtail } func controller(controller: nsfetchedresultscontroller, didchangeobject anobject: anyobject, atindexpath indexpath: nsindexpath?, forchangetype type: nsfetchedresultschangetype, newindexpath: nsindexpath?) { switch type { case .insert: tableview.insertrowsatindexpaths([newindexpath!], withrowanimation: .fade) case .delete: tableview.deleterowsatindexpaths([indexpath!], withrowanimation: .fade) case .update: self.configurecell(tableview.cellforrowatindexpath(indexpath!)! as! customtableviewcell, withobject: anobject as! nsmanagedobject) case .move: tableview.moverowatindexpath(indexpath!, toindexpath: newindexpath!) } }
it seems issue of framing because not image view 2 other labels date , other label missing, adding constraints it?
Comments
Post a Comment