【发布时间】:2014-08-08 06:34:51
【问题描述】:
我有一个 字典数组,如下所示:
(
{ key = 1, value = 40},
{ key = 4, value = 50},
{ key = 8, value = 60}
}
这些是这样的,
for >=1 项目成本是 40,
for >=4 项目成本是 50 和类似的明智。
我想获得 5 的值,在本例中为 50。
我试过的一段代码是:
NSMutableArray *wallpaperPriceArray = [[NSMutableArray alloc]init]; // Assuming this has all the dictionary values
float wallpaperPriceValue = 0;
int itemNumber = 0;
for (int i = 0; i<wallpaperPriceArray.count; i++) {
int check = 0;
if(itemNumber >= [[wallpaperPriceArray objectAtIndex:i] intValue])
{
wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i] objectForKey:@"value"] floatValue];
check++;
}
if(i + 1 <= wallpaperPriceArray.count)
{
if(itemNumber >= [[wallpaperPriceArray objectAtIndex:i+1] intValue] && itemNumber < [[wallpaperPriceArray objectAtIndex:i+1] intValue])
{
wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i+1] objectForKey:@"value"] floatValue];
check++;
if(check == 2)
{
break ;
}
}
}
if(i + 2 <= wallpaperPriceArray.count)
{
if(itemNumber >= [[wallpaperPriceArray objectAtIndex:i+2] intValue] && itemNumber < [[wallpaperPriceArray objectAtIndex:i+2] intValue])
{
wallpaperPriceValue = [[[wallpaperPriceArray objectAtIndex:i+2] objectForKey:@"value"] floatValue];
check++;
if(check == 2)
{
break ;
}
}
}
【问题讨论】:
-
您尝试的代码在哪里?
-
请看一下尝试的代码\
标签: ios objective-c cocoa-touch nsdictionary nspredicate