-1

我有两个 NSMutableArrays(arrayContainsGoodClicks 和 arrayContainsBadClicks)。当相关的好和坏按钮被点击时,我正在用一些 NSTimeInterval 值初始化这些数组。现在我的要求是,我从带有一些 TimeIntervals 的 web 服务调用中得到响应。现在,我想将我从 Web 服务响应中获得的 NSTimeInterval 值与我存储在两个数组中的值进行比较。请在代码下方找到。

question answer="t" qno="1" tin="71" title="Greet" tout="73"
question answer="t" qno="2" tin="74" title="Have Name Tag" tout="77
question answer="t" qno="3" tin="78" title="Greet" tout="83"

我收到上述格式的回复。我正在解析我的文件并存储 NSTimeInterval 值的相关详细信息。现在我想比较 71 和 73 秒(分别为 74 和 77,78 和 83)之间的时间间隔。我有我的数组,其中包含用户单击“好”和“坏”按钮的所有 timeInterval 值。

    -(void)onClickOfGood{
//NSLog(@"The current playback time in good:%g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
[arrayContainsGoodClicks addObject:goodTimeIntervals];
NSLog(@"The total count of Array is: %i",[arrayContainsGoodClicks count]);
NSLog(@"The Array contains : %@",arrayContainsGoodClicks);}

-(void)onClickOfBad{
NSLog(@"The current playback time in bad: %g",moviePlayerController.currentPlaybackTime);
currentPlaybackTime = moviePlayerController.currentPlaybackTime;
NSNumber *goodTimeIntervals = [NSNumber numberWithDouble:currentPlaybackTime];
[arrayContainsBadClicks addObject:goodTimeIntervals];
NSLog(@"The total count of Array is: %i",[arrayContainsBadClicks count]);
NSLog(@"The Array contains Bad Clicks are: %@",arrayContainsBadClicks);}

我的数组包含以下示例详细信息...

The Array containing Good Clicks are : (
"2.065027933",
"3.153256308",
"4.216946226",
"4.94465584",
"5.688772132",
"6.48904879",
"7.256447126",
"8.000711516000001",
"8.760312588",
"9.537493762",
"10.45637486",
"11.153212146",
"11.880587144",
"12.672884372",
"13.52852395"

)

The Array containing Bad Clicks are: (
"2.70485684",
"3.713548251",
"4.593316639",
"5.353822771",
"6.049754725",
"6.930190204",
"7.592959653",
"8.353438538000001",
"9.074305708000001",
"9.905327347",
"10.809726701",
"11.448938757",
"12.321753456",
"14.106061449"

)

有人可以帮助我如何比较我的数组中的 NSTimeIntervals 和收到的响应吗?

4

1 回答 1

3

如果您拥有正确格式的数据,这似乎很简单。NSTimeInterval 是一个typedef double,因此您可以使用基本运算符进行比较

for(NSNumber* click in arrayContainsGoodClicks) {
    NSTimeInterval clickTimeInterval = [click doubleValue];     
    if(clickTimeInterval > 71.0 && clickTimeInterval < 73.0 ) {
       ...
    }
}
于 2012-04-09T16:13:04.730 回答