Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Weather App with Swift (Retired) Displaying Our Weather Data Adding a Refresh Button

Refresh Button Crash

Crashed when I press refresh button. Followed exactly as instructed and even tried to copy/paste teacher's code still didnt work. Here's the error I see:

unrecognized selector sent to instance 0x7a326b10

Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Stormy.ViewController refresh:]: unrecognized selector sent to instance 0x7a326b10'

*** First throw call stack: ( 0 CoreFoundation 0x005f9946 __exceptionPreprocess + 182 1 libobjc.A.dylib 0x01fd5a97 objc_exception_throw + 44 2 CoreFoundation 0x006015c5 -[NSObject(NSObject) doesNotRecognizeSelector:] + 277

Please help... Thanks

Stone Preston
Stone Preston
42,016 Points

post your code where you call the refresh method and where you define the method itself

The code can be found in course "Build a Weather App with Swift" -> "Adding a Refresh Button" I only included the parts related to the refresh button below. The only difference is I named precipitationLabel as rainLabel; if I name it precipitationLabel it will run into an error:

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<Stormy.ViewController 0x7c843580> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key rainLabel.'


The following is the code after i changed the precipitationLabel to rainLabel:

```class ViewController: UIViewController { ... @IBOutlet weak var refreshButton: UIButton! @IBOutlet weak var refreshActivityIndicator: UIActivityIndicatorView!

override func viewDidLoad() {
    refreshActivityIndicator.hidden = true

func getCurrentWeatherData() -> Void { ... ... ... self.rainLabel.text = "(currentWeather.precipProbability)" ...

                //Stop refresh animation
                self.refreshActivityIndicator.hidden = true
                self.refreshButton.hidden = false

@IBAction func refresh() { getCurrentWeatherData() refreshButton.hidden = true refreshActivityIndicator.hidden = false refreshActivityIndicator.startAnimating() } }

2 Answers

Stone Preston
Stone Preston
42,016 Points

try deleting the refresh button, readding it, and reconnecting it to the refresh IBAction

Thanks buddy. Will try tmr morning n let you know.

Rajiv Barton
Rajiv Barton
12,051 Points

I was having the same issue. I went into my utility area and clicked on the last button called the "connections inspector". I then clicked on the refresh button and where it says "Touch Up Inside" I had two "View Controller Refresh" connections. I deleted the extra one and boom it works. Hope that helps!

Niklas Peterson
Niklas Peterson
12,084 Points

Made the same mistake, hehe thanks for pointing it out :)