Kal icon indicating copy to clipboard operation
Kal copied to clipboard

KalViewController cannot be instantiated through xib

Open shawnwall opened this issue 14 years ago • 4 comments

Your examples only show the viewcontroller being instantiated and pushed. If I try to place a KalViewController as a view inside of a navigation controller, I get the following exception when I try to access the view:

*** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Failed to find corresponding tile for date 0/0/0' *** Call stack at first throw: ( 0 CoreFoundation 0x02505919 __exceptionPreprocess + 185 1 libobjc.A.dylib 0x026535de objc_exception_throw + 47 2 CoreFoundation 0x024be078 +[NSException raise:format:arguments:] + 136 3 Foundation 0x000d28cf -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 116 ...

It looks like the we need a force the init call with today's date somehow. Can you document this?

shawnwall avatar Aug 16 '10 20:08 shawnwall

Kal was never tested using Interface Builder because I don't use IB. If you'd like to figure out a fix, please go ahead. Thanks.

klazuka avatar Aug 16 '10 21:08 klazuka

The function initWithCoder needs to be implemented for it to work with interface builder. I did:

  • (id) initWithCoder:(NSCoder *)aDecoder { return [self initWithSelectedDate:[NSDate date]]; }

to work for a very basic implemention

Kelend avatar Sep 18 '10 03:09 Kelend

Kelend's change is also needed if you want to invoke an instance of KalViewController inside a Storyboard file (iOS 5 SDK). Without this change, attempting to do this will result in the following:

*** Assertion failure in -[KalMonthView tileForDate:], /Users/jsmith/Developer/Kal/src/KalMonthView.m:84

mharsch avatar Jul 25 '11 19:07 mharsch

Adding the following line to KalViewController.m solves the issue:

-(id)initWithCoder:(NSCoder *)aDecoder{return [self init];}

mountainMath avatar Jan 31 '12 22:01 mountainMath