这段代码有什么问题?
NSDate *matchDateCD = [[object valueForKey:@"matchDate"] description]; // from coredata NSDate NSDate *add90Min = [matchDateCD dateByAddingTimeInterval:5400]; if ( matchDateCD >=[NSDate date] || add90Min <= matchDateCD ) { cell.imageView.image = [UIImage imageNamed: @"r.gif"];//Show image in the table }
如果匹配运行或90分钟,我需要在表中显示此图像
解决方法
我不知道你调用valueForKey是什么对象:on,但是假定它返回一个NSDate对象,你对description的额外调用将会将一个NSString(描述的返回值)分配给matchDateCD.这不是你想要做的.
这是你想要做的:
NSDate *matchDateCD = [object valueForKey:@"matchDate"]; NSDate *add90Min = [matchDateCD dateByAddingTimeInterval:(90*60)]; // compiler will precompute this to be 5400,but indicating the breakdown is clearer if ( [matchDateCD earlierDate:[NSDate date]] != matchDateCD || [add90Min laterDate:matchDateCD] == add90Min ) { cell.imageView.image = [UIImage imageNamed: @"r.gif"];//Show image in the table }