"Controller Cannot Be nil" on binding NSTextField
"Controller Cannot Be nil" on binding NSTextField
- Subject: "Controller Cannot Be nil" on binding NSTextField
- From: Johnny Lundy <email@hidden>
- Date: Mon, 12 May 2008 21:01:09 -0400
I am stuck on this error.
2008-05-12 20:58:58.257 TimerTest[65919:10b] An uncaught exception was
raised
2008-05-12 20:58:58.259 TimerTest[65919:10b] Controller cannot be nil
2008-05-12 20:58:58.260 TimerTest[65919:10b] *** Terminating app due
to uncaught exception 'NSInvalidArgumentException', reason:
'Controller cannot be nil'
My code is to make a countdown timer, displayed in 3 NSTextFields for
the hours, minutes and seconds.
The code works fine, as you see in the log output below.
However, when I bind one of the NSTextFields to any of the properties
hours, minutes, seconds, or their string equivalents through an
instance of my class, I get the runtime error "controller cannot be
nil" and the nib does not load. It loads fine if I uncheck that binding.
IB: three text fields, no controllers, one NSObject (deadline) with
class of Deadline to instantiate the class. Text fields attempted to
bind their value to properties of this instance, e.g., deadline.hours
or deadline.minutes.
Code:
// Deadline.h
#import <Cocoa/Cocoa.h>
@interface Deadline : NSObject
{
NSTimeInterval timeToDeadline, deadlineHours;
NSTimer *deadlineTimer;
NSCalendarDate *startTime, *endTime;
int hours, minutes, seconds;
NSString *hoursString, *minutesString, *secondsString;
}
@property (readwrite) NSTimeInterval timeToDeadline;
@property (readwrite) NSTimeInterval deadlineHours;
@property (readwrite, copy) NSCalendarDate *startTime;
@property (readwrite, copy) NSCalendarDate *endTime;
@property (readwrite) int hours;
@property (readwrite) int minutes;
@property (readwrite) int seconds;
@property (readwrite, copy) NSString *hoursString;
@property (readwrite, copy) NSString *minutesString;
@property (readwrite, copy) NSString *secondsString;
@end
// Deadline.m
#import "Deadline.h"
@implementation Deadline
@synthesize timeToDeadline, deadlineHours, startTime, endTime, hours,
minutes, seconds, hoursString, minutesString, secondsString;
- (void) init
{
deadlineTimer = [NSTimer scheduledTimerWithTimeInterval:1.0
target:self selector:@selector(updateTime:) userInfo:nil repeats:YES];
self.deadlineHours = 24;
self.startTime = [NSCalendarDate calendarDate]; //Current date
self.endTime = [startTime dateByAddingYears:0 months:0 days:0
hours:self.deadlineHours minutes:0 seconds:0];
}
- (void) updateTime:aTimer
{
[self.endTime years:NULL months:NULL days:NULL hours:&hours
minutes:&minutes seconds:&seconds sinceDate:[NSCalendarDate
calendarDate]];
NSLog(@"Time Left: Hours: %d Minutes:%d Seconds:%d\n", hours,
minutes, seconds);
self.hoursString = [[NSNumber numberWithInt: self.hours] stringValue];
}
@end
[Session started at 2008-05-12 20:25:45 -0400.]
2008-05-12 20:25:46.943 TimerTest[65851:10b] Time Left: Hours: 23
Minutes:59 Seconds:58
2008-05-12 20:25:47.943 TimerTest[65851:10b] Time Left: Hours: 23
Minutes:59 Seconds:57
2008-05-12 20:25:48.943 TimerTest[65851:10b] Time Left: Hours: 23
Minutes:59 Seconds:56
I Googled this error and the only thing that came up was a guy totally
re-built his nib file and the error went away.
Has anyone seen this?
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden