Reputation: 203
I have an app with a UIViewController with custom UIViews in it. I want to set a variable in that custom UIView and it doesn't update... I have done this a thousand times and it always worked but this time it doesn't and I really can't figure out what I'm doing wrong, any help is welcome!
In my viewcontroller:
var sjablonview: sjablonPicker!
sjablonview = sjablonPicker(frame: CGRect(x: btnUndo.frame.origin.x, y: DrawingView.frame.origin.y,
width: (btnX.frame.origin.x + btnX.frame.size.width) - btnUndo.frame.origin.x, height: 250))
sjablonview.alpha = 1
sjablonview.mpUitklapping = 300
self.view.addSubview(sjablonview)
In my custom UIView:
class sjablonPicker: UIView {
var mpUitklapping = CGFloat(100)
override init(frame: CGRect){
super.init(frame: frame)
print(mpUitklapping) // --> output = 100 and not 300
...
Upvotes: 0
Views: 68
Reputation: 54775
You are printing from inside your initialiser. Your view is initialized before you change the value of mpUitklapping
. Your initializer gets called from this line:
sjablonview = sjablonPicker(frame: CGRect(x: btnUndo.frame.origin.x, y: DrawingView.frame.origin.y, width: (btnX.frame.origin.x + btnX.frame.size.width) - btnUndo.frame.origin.x, height: 250))
The value gets changed, you just don't print the updated value.
Upvotes: 1