ios - IBOutlet nil after refreshing data -


i'm using xcode 6.3.1 , i'm facing weird problem can't figure out.

i have view controller on storyboard opened modal segue. when viewcontroller opened loads data backend (parse) looks first on cache , shows cached data (if exists) while updated data server retrieved on background. process next:

  1. get cached data
  2. if cached data exists update interface
  3. request server data (in background)
  4. when data arrives update interface

everything works fine until step 4. when try refresh interface half of @iboutlets nil , of course app crashes.

what missing??

here's code:

override func viewdidload() {     super.viewdidload()      // additional setup after loading view.      //eventid set when viewcontroller instantiated     if eventid != nil {         loadevent(eventid)     } }  func loadevent(id: string) {      var query = event.query()     query?.cachepolicy = util.getcachepolicy()   //first in cache, request network data     query?.getobjectinbackgroundwithid(id, block: { (event: pfobject?, error: nserror?) -> void in          if error == nil {              var updatedevent = event as! event             self.event = updatedevent             self.updatelayout()                 //when self.updatelayout() called cached data              //all iboutlets fine when it's called second time,             //with data server half of iboutlets nil         }     }) }  func updatelayout() {      if event != nil {          eventtitle.text = event.name          var palettecolor : uicolor!         var location = event.location         var locationname = location["name"] as! string         eventlocation.text = nsstring(format: nslocalizedstring("event_subtitle", comment: ""), event.formattedtimes(), locationname) string          eventdescription.text = event.abstract          if event.palettecolor != 0 {             palettecolor = util.colorfromint(event.palettecolor)             eventheader.backgroundcolor = palettecolor             speakersblocktitle.textcolor = palettecolor               mapbutton.tintcolor = palettecolor         }          if event.hasphoto() {              self.eventphoto.file = event.eventphoto             self.eventphoto.loadinbackground({ (image:uiimage?, error:nserror?) -> void in                 uiview.animatewithduration(0.5, animations: { () -> void in                      self.eventphoto.alpha = 1.0                 })             })          } else {             self.eventphoto.removefromsuperview()             if palettecolor == nil {                 palettecolor = eventheader.backgroundcolor             }             actionbar.backgroundcolor = palettecolor         }          if event.speaker.isdataavailable() {              var speaker = event.speaker             speakername.text = speaker["name"] as? string             speakerinfo.text = speaker["speakerinfo"] as? string             speaker["speakerphoto"]?.getdatainbackgroundwithblock({ (imagedata:nsdata?, error:nserror?) -> void in                 if error == nil {                     self.speakerphoto.image = uiimage(data:imagedata!)                     self.speakerphoto.layer.cornerradius = self.speakerphoto.frame.size.width/2                     self.speakerphoto.clipstobounds = true                 }             })         } else {             speakerblock.removefromsuperview()         }          uiview.animatewithduration(0.5, animations: { () -> void in              self.eventheader.alpha = 1.0             self.eventdescription.alpha = 1.0             self.speakerblock.alpha = 1.0             self.mapbutton.alpha = 1.0         })     } } 

this nil iboutlets: this nil iboutlets:

since code in comment above doesn't display correctly, here's comment again:

something this:

@iboutlet weak var myoutlet: uibutton! {     didset {         if myoutlet == nil {             // put breakpoint on next line             println("myoutlet set nil")         }     } } 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -