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 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.'

Thanks.

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() {
    super.viewDidLoad()
    refreshActivityIndicator.hidden = true
    getCurrentWeatherData()
}

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

                //Stop refresh animation
                self.refreshActivityIndicator.stopAnimating()
                self.refreshActivityIndicator.hidden = true
                self.refreshButton.hidden = false
            })                
        }            
    })        
    downloadTask.resume()
}

@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 :)