将参数发送到方法 - NSTimeInterval

时间:2013-03-27 20:07:58

标签: iphone objective-c methods parameters

我正在尝试将NSTimeInterval发送到一个方法,该方法将在后台线程上运行的方法的主线程上运行。不幸的是,我收到了这个错误:

Sending 'NSTimeInterval' (aka 'double') to parameter of incompatible type 'id'

这是我的代码 - 知道出了什么问题吗?

首先,我设置了我的NSTimerInterval,并调用performSelectorOnMainThread:

NSTimeInterval delayBetweenIntAdsNSTimeInterval = [responseStringTimeBetweenAds doubleValue];
[self performSelectorOnMainThread:@selector(startTimerForAds:) withObject:delayBetweenIntAdsNSTimeInterval waitUntilDone:NO];

这是我正在调用的方法的代码:

-(void)startTimerForAds:(NSTimeInterval)intervalBetweenAds {
}

有关该问题的任何想法?

谢谢,

更新

我打电话:

[self performSelectorOnMainThread:@selector(startTimerForAds:) withObject:@(delayBetweenIntAds) waitUntilDone:NO];

这是方法:

-(void)startTimerForAds:(NSInteger *)intervalBetweenIntAdsInteger {
}

但是通过该调用(在对象上),XCode显示:

Illegal type 'NSInteger *' (aka 'int *') used in a boxed expression

它显示在[intervalBetweenIntAdsInteger doubleValue]:

之上
Bad receiver type 'NSInteger *' (aka 'int *')

1 个答案:

答案 0 :(得分:3)

NSTimeInterval不是对象。试试NSNumber,应该这样做:

NSTimeInterval delayBetweenIntAdsNSTimeInterval = [responseStringTimeBetweenAds doubleValue];
[self performSelectorOnMainThread:@selector(startTimerForAds:) withObject:@(delayBetweenIntAdsNSTimeInterval) waitUntilDone:NO];


-(void)startTimerForAds:(NSNumber *)intervalBetweenAds {

     NSTimeInterval i = [intervalBetweenAds doubleValue];

}

由于您的更新而更新:

[self performSelectorOnMainThread:@selector(startTimerForAds:) withObject:@(delayBetweenIntAds) waitUntilDone:NO];

-(void)startTimerForAds:(NSNumber *)intervalBetweenAds {
     int i = [intervalBetweenAds intValue];
}