Objective-C:从Integer变量触发fireate?

时间:2011-10-03 20:07:18

标签: objective-c integer uilocalnotification

我想使用“炒作”进行本地通知。如何使用包含秒的整数变量来触发fireate?

int intTime;
intTime=([mAhLabel.text floatValue]/chargerSlider.value)*1.5*3600;
notif.fireDate = (intTime);

我知道上面的代码是错的,只是给我一个提示家伙!提前谢谢。

P.S。当我尝试使用这段代码时,我得到“不兼容的整数到指针转换,从int分配'NSDate *。”

2 个答案:

答案 0 :(得分:3)

fireDate必须是NSDate*,因为您知道您的解决方案不正确。如果您的计算结果是您想要从当前时间开始的秒数,则以下代码将起作用。

NSTimeInterval time = ([mAhLabel.text floatValue]/chargerSlider.value)*1.5*3600;
notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:time];

同时确保使用0无法通过设置最小值或检查分割前的值来除chargerSlider.value。否则结果将是NaN

答案 1 :(得分:1)

UILocalNotification上的fireDate属性属于NSDate类型。您需要首先使用整数创建NSDate作为您需要的未来时间量。例如,如果我们正在寻找一个从现在开始一个小时的开火日期,它将会是这样的。

notif.fireDate = [NSDate dateWithTimeIntervalSinceNow:3600];