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 Implementing the Detail View Adding UI Elements

Getting an error

I'm getting this error when I click on the weather for a day in the table view. It crashes immediately and gives me this error "2015-08-12 09:25:40.456 Stormy[86265:5195171] -[Stormy.detailBackgroundView setText:]: unrecognized selector sent to instance 0x7fc85b574e00 2015-08-12 09:25:40.458 Stormy[86265:5195171] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Stormy.detailBackgroundView setText:]: unrecognized selector sent to instance 0x7fc85b574e00' *** First throw call stack: ( 0 CoreFoundation 0x000000010f25ac65 exceptionPreprocess + 165 1 libobjc.A.dylib 0x0000000111007bb7 objc_exception_throw + 45 2 CoreFoundation 0x000000010f2620ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205 3 CoreFoundation 0x000000010f1b813c ___forwarding_ + 988 4 CoreFoundation 0x000000010f1b7cd8 CF_forwarding_prep_0 + 120 5 Stormy 0x000000010ebde04e _TFC6Stormy14ViewController13configureViewfS0_FT_T + 2382 6 Stormy 0x000000010ebdd67a TFC6Stormy14ViewController11viewDidLoadfS0_FT_T + 122 7 Stormy 0x000000010ebdd6f2 TToFC6Stormy14ViewController11viewDidLoadfS0_FT_T + 34 8 UIKit 0x000000010fe6c1d0 -[UIViewController loadViewIfRequired] + 738 9 UIKit 0x000000010fe6c3ce -[UIViewController view] + 27 10 UIKit 0x000000010fe91257 -[UINavigationController startCustomTransition:] + 633 11 UIKit 0x000000010fe9d37f -[UINavigationController _startDeferredTransitionIfNeeded:] + 386 12 UIKit 0x000000010fe9dece -[UINavigationController __viewWillLayoutSubviews] + 43 13 UIKit 0x000000010ffe86d5 -[UILayoutContainerView layoutSubviews] + 202 14 UIKit 0x000000010fdbb9eb -[UIView(CALayerDelegate) layoutSublayersOfLayer:] + 536 15 QuartzCore 0x0000000114215ed2 -[CALayer layoutSublayers] + 146 16 QuartzCore 0x000000011420a6e6 _ZN2CA5Layer16layout_if_neededEPNS_11TransactionE + 380 17 QuartzCore 0x000000011420a556 _ZN2CA5Layer28layout_and_display_if_neededEPNS_11TransactionE + 24 18 QuartzCore 0x000000011417686e _ZN2CA7Context18commit_transactionEPNS_11TransactionE + 242 19 QuartzCore 0x0000000114177a22 _ZN2CA11Transaction6commitEv + 462 20 QuartzCore 0x00000001141780d3 _ZN2CA11Transaction17observer_callbackEP19CFRunLoopObservermPv + 89 21 CoreFoundation 0x000000010f18dca7 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION_ + 23 22 CoreFoundation 0x000000010f18dc00 __CFRunLoopDoObservers + 368 23 CoreFoundation 0x000000010f183a33 __CFRunLoopRun + 1123 24 CoreFoundation 0x000000010f183366 CFRunLoopRunSpecific + 470 25 GraphicsServices 0x0000000113d3ea3e GSEventRunModal + 161 26 UIKit 0x000000010fd3b8c0 UIApplicationMain + 1282 27 Stormy 0x000000010ebf9df7 main + 135 28 libdyld.dylib 0x000000011173d145 start + 1 29 ??? 0x0000000000000001 0x0 + 1 ) libc++abi.dylib: terminating with uncaught exception of type NSException" It highlights this "class AppDelegate: UIResponder, UIApplicationDelegate {" In the app delegate file. Do you have any idea where the problem is? Thanks, Kyle

Stone Preston
Stone Preston
42,016 Points

can you post your code related to the table view?

2 Answers

Here is the detailBackgroundView:

import UIKit

class detailBackgroundView: UIView {

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.

*/

override func drawRect(rect: CGRect) {
    //// Color Declarations
    var lightPurple: UIColor = UIColor(red: 0.377, green: 0.075, blue: 0.778, alpha: 1.000)
    var darkPurple: UIColor = UIColor(red: 0.060, green: 0.036, blue: 0.202, alpha: 1.000)

    let context = UIGraphicsGetCurrentContext()

    //// Gradient Declarations
    let purpleGradient = CGGradientCreateWithColors(CGColorSpaceCreateDeviceRGB(), [lightPurple.CGColor, darkPurple.CGColor], [0, 1])

    //// Background Drawing
    let backgroundPath = UIBezierPath(rect: CGRectMake(0, 0, self.frame.width, self.frame.height))
    CGContextSaveGState(context)
    backgroundPath.addClip()
    CGContextDrawLinearGradient(context, purpleGradient,
        CGPointMake(160, 0),
        CGPointMake(160, 568),
        UInt32(kCGGradientDrawsBeforeStartLocation) | UInt32(kCGGradientDrawsAfterEndLocation))
    CGContextRestoreGState(context)

    //// Sun Path

    let circleOrigin = CGPointMake(0, 0.80 * self.frame.height)
    let circleSize = CGSizeMake(self.frame.width, 0.65 * self.frame.height)

    let pathStrokeColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.390)
    let pathFillColor = UIColor(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.100)


    //// Sun Drawing
    var sunPath = UIBezierPath(ovalInRect: CGRectMake(circleOrigin.x, circleOrigin.y, circleSize.width, circleSize.height))
    pathFillColor.setFill()
    sunPath.fill()
    pathStrokeColor.setStroke()
    sunPath.lineWidth = 1
    CGContextSaveGState(context)
    CGContextSetLineDash(context, 0, [2, 2], 2)
    sunPath.stroke()
    CGContextRestoreGState(context)

}

}

And here is the viewController:

import UIKit

class ViewController: UIViewController {

var dailyWeather: DailyWeather? {
    didSet {
        configureView()

    }
}

@IBOutlet weak var weatherIcon: UIImageView?
@IBOutlet weak var summaryLabel: UILabel?
@IBOutlet weak var sunriseTimeLabel: UILabel?
@IBOutlet weak var sunsetTimeLabel: UILabel?
@IBOutlet weak var lowTemperatureLabel: UILabel?
@IBOutlet weak var highTemperatureLabel: UILabel?
@IBOutlet weak var precipitationlabel: UILabel?
@IBOutlet weak var humidityLabel: UILabel?


  override func viewDidLoad() {
    super.viewDidLoad()

    // Do any additional setup after loading the view, typically from a nib.
    configureView()
}
func configureView() {
    if let weather = dailyWeather {

        weatherIcon?.image = weather.largeIcon
        summaryLabel?.text = weather.summary
        sunriseTimeLabel?.text = weather.sunriseTime
        sunsetTimeLabel?.text = weather.sunsetTime
        if let lowTemp = weather.minTemperature,
            let highTemp = weather.maxTemperature,
            let rain = weather.precipChance,
            let humidity = weather.humidity {
                lowTemperatureLabel?.text = "\(lowTemp)ΒΊ"
                highTemperatureLabel?.text = "\(highTemp)ΒΊ"
                precipitationlabel?.text = "\(rain)%"
                humidityLabel?.text = "\(humidity)%"
        }
        self.title = weather.day
    }
    if let buttonFont = UIFont(name: "HelveticaNeue-Thin", size: 20.0){
        let barButtonrAttributesDictionary: [NSObject: AnyObject]? = [
            NSForegroundColorAttributeName : UIColor.whiteColor(), NSFontAttributeName: buttonFont
        ]
        UIBarButtonItem.appearance().setTitleTextAttributes(barButtonrAttributesDictionary, forState: .Normal)
    }
}
override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

}

If you need anything else, just ask.

Thanks,

Kyle

Patrick Egan
Patrick Egan
3,634 Points

Hi Kyle

If you are still looking for an answer I would like to see your WeeklyTableViewController.swift file.

I had a similar problem but I managed to fix it.

Cheers