ios - fatal error: unexpectedly found nil while unwrapping an Optional value (cellForRowAtIndexPath) (Xib Custom Cell Swift) -


i error stated in topic unknown reason cell reference(in downloadprofilepicture) visible. basically, trying replicate/adapt done in lazytableviewimages

override func viewdidload() {          super.viewdidload()          self.tableview.registerclass(topcell.self, forcellreuseidentifier: "topcell")          self.tableview.registerclass(contentcell.self, forcellreuseidentifier: "contentcell")          tableview.registernib(uinib(nibname: "topcell", bundle: nil), forcellreuseidentifier: "topcell")          tableview.registernib(uinib(nibname: "contentcell", bundle: nil), forcellreuseidentifier: "contentcell")          self.tableview.delegate = self          self.tableview.datasource = self }   func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {     let nodecount = arrayofposts.count;     let cell = uitableviewcell()      tableview.dequeuereusablecellwithidentifier("topcell", forindexpath: indexpath) as! topcell         if (nodecount > 0)         {             if (indexpath.row % 2 == 0){                 // set cell representing app                 var cell = tableview.dequeuereusablecellwithidentifier("topcell", forindexpath: indexpath) as! topcell                 let post = arrayofposts[indexpath.row]                 cell.username.text = post.username                 cell.timesinceposted.text = post.timesinceposted                 // load cached images; defer new downloads until scrolling ends                 if (post.profileimage == nil)                 {                     if (!tableview.dragging && !tableview.decelerating)                     {                         downloadprofileimage(post, indexpath: indexpath)                         return cell                     }                     // if download deferred or in progress, return placeholder image                     cell.profileimage.image = uiimage(named: "titanic.jpg")                                        }                 else                 {                        cell.profileimage.image = post.profileimage                 }                 return cell             }  func downloadprofileimage(post: post, indexpath: nsindexpath){         println(self.tableview.indexpathsforvisiblerows())         println(indexpath)         let cell:topcell = self.tableview.cellforrowatindexpath(indexpath) as! topcell         cell.profileimage.image = uiimage(named: "img1")     } 

visiblepaths:

 (     "<nsindexpath: 0x7888f7b0> {length = 2, path = 0 - 0}",     "<nsindexpath: 0x788a4d60> {length = 2, path = 0 - 1}" ) 

cell:

<nsindexpath: 0x788a3c80> {length = 2, path = 0 - 1} 

in method table view cell created twice. try structure this, must guaranteed table view cell returned

func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell {   let nodecount = arrayofposts.count;   let cell = tableview.dequeuereusablecellwithidentifier("topcell", forindexpath: indexpath) as! topcell   if (nodecount > 0)  {     if (indexpath.row % 2 == 0){       let post = arrayofposts[indexpath.row]       cell.username.text = post.username       cell.timesinceposted.text = post.timesinceposted       // load cached images; defer new downloads until scrolling ends       if (post.profileimage == nil)       {         if (!tableview.dragging && !tableview.decelerating)         {           downloadprofileimage(post, indexpath: indexpath)           return cell         }         // if download deferred or in progress, return placeholder image         cell.profileimage.image = uiimage(named: "titanic.jpg")       }       else       {         cell.profileimage.image = post.profileimage       }     }   }   return cell } 

Comments

Popular posts from this blog

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -