ios - Why not change my background and title after accelerometer data is recieved? SWIFT -


print , func call successful both time, background , title change when restart app , works 1 times. here code:

    var motionmanager = cmmotionmanager()  override func viewdidappear(animated: bool) {     super.viewdidappear(animated)     startmotionmanager() }  func startmotionmanager() {      if motionmanager.accelerometeravailable {     motionmanager.accelerometerupdateinterval = 0.2     motionmanager.startaccelerometerupdatestoqueue(nsoperationqueue(), withhandler: {         [weak self] (data, error) in          print(data!.acceleration.z)          if(data!.acceleration.z > 0.8) {             self!.win()             print("win")         }          if (data!.acceleration.z < -0.9){             self!.pass()             print("pass")         }         return         })     }  }  func pass() {     print("passfunction")     self.testlabel.text = "pass"     self.view.backgroundcolor = uicolor.redcolor() }  func win() {     testlabel.text = "win"     view.backgroundcolor = uicolor.greencolor() } 

}

my main goal call func win when acceleration.z > 0.8 change title label "win" , view background green if acceleration.z < -0.9 call pass function change background red , etc...

thanks help!

i tired day solve this. after posted question found problem in code.

    func pass() {        nsoperationqueue.mainqueue().addoperationwithblock {         self.testlabel.text = "pass"        self.view.backgroundcolor = uicolor.redcolor()        }     } 

Comments

Popular posts from this blog

Delphi XE2 Indy10 udp client-server interchange using SendBuffer-ReceiveBuffer -

Qt ActiveX WMI QAxBase::dynamicCallHelper: ItemIndex(int): No such property in -

Enable autocomplete or intellisense in Atom editor for PHP -