问题
- (id)initWithCoder:(NSCoder *)aDecoder
{
dueDate = [NSDate date];
}
- (void)viewDidLoad
{
[super viewDidLoad];
NSDateFormatter *formatter = [[[NSDateFormatter alloc] init] autorelease];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
self.lbDueDate.text = [formatter stringFromDate:dueDate];
}
In init method I declared dueDate = [NSDate date]. But when I debug, at this line
self.lbDueDate.text = [formatter stringFromDate:dueDate];
And Output: (NSDate *) dueDate = 0x0c497390 So what happend ?
回答1:
It means the object's been -dealloc
ed (unless it is nil
). So run with Zombies and message it more often -- after running the static analyzer and reviewing your code.
one problem in the source: dueDate = [NSDate date];
should be dueDate = [[NSDate date] copy];
. another problem is that you don't call through the superclass' designated initializer in your implementation of -initWithCoder:
.
来源:https://stackoverflow.com/questions/15049971/nsdate-ivar-become-not-an-objective-c-object