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 trial
Antoine Streiff
4,649 PointsremoveFromSuperView() and cells = fatal error: unexpectedly found nil while unwrapping an Optional value
I'm doing a little UITableView with a CustomCell in a XIB.
I want to remove views if a bool says FALSE.
So what I did was a little func :
func deleteStackOrNot(valeurPLIST: Bool, stack: UIStackView) {
if valeurPLIST {
stack.hidden = false
} else {
stack.removeFromSuperview()
}
}
and then :
deleteStackOrNot((corpusArray[indexPath.row]["iconesNPBool"] as! Bool), stack: cell.iconesStackOutlet)
It's working great on the first scroll down, on 2 cells. However, when I'm scrolling back to the first cell, I get :
fatal error: unexpectedly found nil while unwrapping an Optional value
Pointing on the function call.
I guess I've removed the outlet, like, "for ever", and now xcode doesnt seems to be able to recreate it…
I've also tried with .hidden but I need to remove it, since the constraints stays when the view is hidden.
Somebody suggested to "add a UIStackView property to the custom cell class to hold the view while it's not in the hierarchy and add it back", but I don't really understand what it would mean…
What do you think ?