Reputation: 4122
In one viewcontroller I have a few UIViews
that constain some text labels and buttons. Depending on what data I receive from my API I either hide some of the UIViews
or populate them with data.
My question now is, can I just hide the UIView
or must I also hide all of the elements that are nested inside the UIView
?
Eg:
myView.hidden = true
myView.userinteractionsEnabled = false
vs
myView.hidden = true
myView.userinteractionsEnabled = false
// And some stuff inside/nested myView
myButton.hidden = true
myButton.userinteractionsEnabled = false
myLabel.hidden = true
Upvotes: 1
Views: 7271
Reputation: 87
Hide the view that the other views are inside of. Hiding a view will also hide its subviews.
Upvotes: 1
Reputation: 6705
It hides the subviews too.
You can test this easily enough in a Playground:
import UIKit
var v = UIView(frame: CGRectMake(0,0, 600, 600))
v.backgroundColor = UIColor.redColor()
var subv = UIView(frame: CGRectMake(100,100, 200, 200))
subv.backgroundColor = UIColor.blueColor()
var subv2 = UIView(frame: CGRectMake(10,10, 50, 50))
subv2.backgroundColor = UIColor.whiteColor()
subv.addSubview(subv2)
v.addSubview(subv)
subv.hidden = true
v
Here is the result:
Upvotes: 2