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

谁说胖子不能爱 提交于 2019-12-13 02:51:53

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!