1

so I'm trying to make an analog clock app for practice. I have ClockView.h/.m configured correctly and the analog clock works fine. My only problem is that whenever I delete one instance of the clock view from the main view controller, the application crashes and throws an exception. Anyone have an insight on why this is happening? Here's the code for my View Controller:

#import <UIKit/UIKit.h>
#import "ClockView.h"

@interface ViewController : UIViewController <UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) ClockView *clockView;

@property (strong, nonatomic) IBOutlet ClockView *clockView1;

@end

Whenever I comment out the first property, the app crashes (even though I don't use it anywhere else in my code). It is linked to the UIViewController in Storyboard and the second property is linked to a UIView.

Here's the code for ViewController.m

@implementation ViewController


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
    }
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];

    [self.clockView1 setClockBackgroundImage:[UIImage imageNamed:@"clock-background.png"].CGImage];
    [self.clockView1 setHourHandImage:[UIImage imageNamed:@"clock-hour-background.png"].CGImage];
    [self.clockView1 setMinHandImage:[UIImage imageNamed:@"clock-min-background.png"].CGImage];
    [self.clockView1 setSecHandImage:[UIImage imageNamed:@"clock-sec-background.png"].CGImage];
}
@end

Here is the exception I'm getting;

Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<ViewController 0x78ea6880> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key clockView.' [....]
*** First throw call stack:

    libc++abi.dylib: terminating with uncaught exception of type NSException
Infineon Labs
  • 91
  • 1
  • 11

1 Answers1

1

This error

"this class is not key value coding-compliant for the key XXXX"

usually means that some UI elements from storyboard has connection to XXXX, in your case that's clockView property.

I would suggest go thru all elements of your UI in storyboard and check in the Connections Inspector that nothing is pointing to XXXX (clockView)

enter image description here

Amir
  • 9,577
  • 11
  • 41
  • 58