简体   繁体   中英

NSDate ivar become <not an Objective-C object>?

- (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 ?

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: .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM