1

我正在尝试将 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 *')
4

1 回答 1

4

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];
}
于 2013-03-27T20:26:01.873 回答