Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialKanish Chhabra
2,151 PointsWhat if I create IBOutlet in the viewDidLoad method? Why won't it work?
What if I create IBOutlet in the viewDidLoad method? Why won't it work?
1 Answer
Jeremy Conley
4,791 PointsAn iboutlet is just a reference to an objet on the storyboard, you want these above your view did load to make it accessible throughout your whole class. You can modify it in your view did load, but I can't see any reason why you would need to create it there.
However, if you're looking to create an object in your viewdidload, like a UILabel, you can always do it without an outlet.
override func viewDidLoad() {
let label = UILabel()
label.frame = CGRect(0,0,somewidth,someheight)
view.addSubview(label)
}
Kanish Chhabra
2,151 PointsKanish Chhabra
2,151 PointsThanks Jeremy, just asked out of curiosity, didn't feel any need to create it in the viewdidload.??
Jeremy Conley
4,791 PointsJeremy Conley
4,791 PointsNothing wrong with curiosity! Glad I could help.