ios - Swift - View not displaying/updating controls even though they are visible -


apologies horrible title, couldn't think of better way put it. code below:

@ibaction func btnsavetapped(sender: uibutton) {     println("save button pressed")     self.startai()     self.btnsave.enabled = false     self.animatebutton(sender)      var boocontinuewithsend:bool = true     (continues) 

when run above code, there no change controls on screen. have stepped through code , each line, there no change. btnsave.enabled, there no change. have confirmed through poing console debugger button not enabled, , yet still displays if is. , yes, have set visibly change depending on state (code below):

self.btnsave.settitlecolor(conbuttontextcolour, forstate: uicontrolstate.normal) self.btnsave.settitlecolor(conbuttontextcolourdisabled, forstate: uicontrolstate.disabled) 

where conbuttontextcolour uicolor.blackcolor , conbuttontextcolourdisabled gray.

it happens activity indicator, have tested manually successfully. when run above code (btnsavetapped), nothing happens (it doesn't display should). create ai programmatically here:

func createai() {     let conaiviewheightwidth:cgfloat = 100     let conheightwidth:cgfloat = 50      self.aiview.settranslatesautoresizingmaskintoconstraints(false)     self.view.addsubview(self.aiview)     self.aiview.backgroundcolor = uicolor(red: 0, green: 0, blue: 0, alpha: 0.3)     self.aiview.layer.cornerradius = 10      var constraintviewheight:nslayoutconstraint = nslayoutconstraint(item: self.aiview, attribute: nslayoutattribute.height, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: conaiviewheightwidth)     var constraintviewwidth:nslayoutconstraint = nslayoutconstraint(item: self.aiview, attribute: nslayoutattribute.width, relatedby: nslayoutrelation.equal, toitem: nil, attribute: nslayoutattribute.notanattribute, multiplier: 1, constant: conaiviewheightwidth)     self.aiview.addconstraints([constraintviewheight, constraintviewwidth])      var constraintviewx:nslayoutconstraint = nslayoutconstraint(item: self.aiview, attribute: nslayoutattribute.centerx, relatedby: nslayoutrelation.equal, toitem: self.view, attribute: nslayoutattribute.centerx, multiplier: 1, constant: 0)     var constraintviewy:nslayoutconstraint = nslayoutconstraint(item: self.aiview, attribute: nslayoutattribute.centery, relatedby: nslayoutrelation.equal, toitem: self.view, attribute: nslayoutattribute.centery, multiplier: 1, constant: 0)     self.view.addconstraints([constraintviewx, constraintviewy])       self.aiactivityindicator.settranslatesautoresizingmaskintoconstraints(false)     self.aiview.addsubview(self.aiactivityindicator)     self.aiactivityindicator.activityindicatorviewstyle = uiactivityindicatorviewstyle.whitelarge       var constraintx:nslayoutconstraint = nslayoutconstraint(item: self.aiactivityindicator, attribute: nslayoutattribute.centerx, relatedby: nslayoutrelation.equal, toitem: self.aiview, attribute: nslayoutattribute.centerx, multiplier: 1, constant: 0)     var constrainty:nslayoutconstraint = nslayoutconstraint(item: self.aiactivityindicator, attribute: nslayoutattribute.centery, relatedby: nslayoutrelation.equal, toitem: self.aiview, attribute: nslayoutattribute.centery, multiplier: 1, constant: 0)     self.view.addconstraints([constraintx, constrainty])      self.aiactivityindicator.hideswhenstopped = true     self.aiactivityindicator.startanimating()      stopai() } 

here 2 routines start , stop ai respectively. because ai subview of aiview hide or unhide that. however, these problems, decided super safe , make sure unhiding , enabling ai.

func startai() {     self.aiview.hidden = false     self.aiactivityindicator.hidden = false     self.aiactivityindicator.startanimating()     println("started ai") }  func stopai() {     self.aiview.hidden = true     println("stopped ai") } 

what doing wrong? in advance.

try code:

view.layoutifneeded() 

implement when changes made


Comments