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

iOS Enhance a Weather App with Table Views Custom Table View Cells Pull To Refresh

Refresh control zPosition crashing the app?

Ok so I was following the pull to refresh video and then I tried typing refreshControl?.layer.zPosition = tableView.backgroundView!.layer.zPosition + 1 but it just crashed my app? The error that it comes up with is: "fatal error: unexpectedly found nil while unwrapping an Optional value"

It must be tableView.backgroundView?.layer.zPosition + 1

The app is unwrapping a null value. If you use "?", the unwrap process will be silently interrupted in case of null value.

2 Answers

I've got the same problem.

I have a custom tableView, and this must be the problem. When i tried optional sign "?" xCode automatically corrects the line like this:

self.refreshControl.layer.zPosition = (self.mainTableView.backgroundView?.layer.zPosition)! + 1

The error is EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subside=0x0)

Also i have a problem in a custom tableView, i made myself a refresh control, which was introduced in weather app course. Everything works fine, but i don't understand, how can i make refreshControl appear above tableView, i want it to be pulled down, not appear behind the tableView.