在数组上显示自定义对象的滑块值

时间:2012-09-17 07:30:14

标签: iphone

我正在开发一个天气应用程序......其基本思想是 从服务获得预测......我做了....添加自定义天气 对象到数组....我做了...... FYI the weather objects contains about 12 poperties....

现在我有一个滑块,我想显示mean or average of two temperature properties from weather objects that i get from an array on the value of slider...,我应该告诉你,该数组包含大约40个对象,滑块最大值为1440分钟....这大约需要12小时

现在主要的问题是,如何在循环中执行此操作并从动态数组中获取对象导致i dont want to hardcode the indexes of the array

我可以得到像这样的东西,也想要这样的东西......

if(sliderValue<180)
weather = [array objectAtIndex:0];

if(sliderValue<360)
weather = [array objectAtIndex:1];

if(sliderValue<540)
weather = [array objectAtIndex:2];

if(sliderValue<720)
weather = [array objectAtIndex:3];

if(sliderValue<810)
weather = [array objectAtIndex:4];


and so on up to slidervalue == 1440

我已经为每个条件做了所有的if else,如果是其他的那个144(从值== 10到值== 1440)所以我认为这样效率不高....

简单的是,我有一个UISlider and whose max value is 1440,并且每隔10个间隔就意味着after every 10 points i want to display average of two values ....这些值存储在存储在NSArray中的自定义对象中。自定义对象是使用Web服务api从XML创建的,所以我确切知道XML将返回多少对象,因此为此我不想硬编码数组的索引并从数组中动态获取对象因为有时候数组可能不包含索引上的对象而应用程序会崩溃......这就是整个故事...希望你能帮我......

main point is displaying and calculating average of two values after every 10 points of the slider value... and as i mentioned the conditions earlier if the value increases by 180 the index increases and next object is fetched from the array....

1 个答案:

答案 0 :(得分:0)

您的问题似乎没有足够的信息。能否更准确地解释一下你的问题,或者举个例子。 我建议你使用Switch Case而不是使用那么多“if-else”。这将改善你的应用程序性能,因为Switch在条件匹配的地方中断,因此执行的比较较少。