ios – 向NSDate添加90分钟

这段代码有什么问题?
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
}

相关文章

当我们远离最新的 iOS 16 更新版本时,我们听到了困扰 Apple...
欧版/美版 特别说一下,美版选错了 可能会永久丧失4G,不过只...
一般在接外包的时候, 通常第三方需要安装你的app进行测...
前言为了让更多的人永远记住12月13日,各大厂都在这一天将应...