加入NSDate 90分钟 [英] Add 90 min to NSDate
本文介绍了加入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分钟,我需要在表格中显示此图像
I need to show this image in the table if the match is running or for 90 min
推荐答案
我不知道对象
是什么,你调用 valueForKey:
on是但假设它返回 NSDate
对象,您对 description
的额外调用将分配 NSString
(描述的返回值)到 matchDateCD
。这不是你想要做的。
I don't know what object
is that you call valueForKey:
on is but presuming it returns an NSDate
object, your additional call to description
will assign an NSString
(the return value of description) to matchDateCD
. That is not what you want to do.
这就是你想要做的事情:
This is what you want to do:
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
}
这篇关于加入NSDate 90分钟的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文