我不能告诉你任何关于objective-c、ios 或uipickerview 的事情......对于算法。这是一些没有特别语言的伪代码:
i = 7 // this is i in your example
offset=420 // This is where you could say you want
// to start at 7:00 (420 minutes after midnight)
// you could use any number here obviously.
counter = offset
while (counter<1440+offset){
counter = counter+i
minutes = counter%60
hours = counter/60 // Use integer division
}
modulous 每次都会通过给您剩余的时间来为您提供分钟数。因此,在您的示例中,分钟数将从 56 => 63 => 3 开始,这就是您想要的。
如果您只想知道给定间隔的分钟和小时数(假设间隔从 0 到 206(一天有 206 个 7 分钟间隔),那么您可以执行以下操作:
minutes = (i*intervalNum) % 60
hours = (i*intervalNum) / 60 // Integer division!
如果您需要一段时间内的间隔数,您可以执行以下操作:
keep a hashmap (again I don't know how objective-c handles these) that maps an hour to a list of the minutes that mark intervals. In your example you could have a hashmap that looks like:
{0 => (0,7,14,21,28,35,42,49,56),
1 => (3,10,17,24,31,38,45,52,59),
2 => (6,13,20,27,34,41,48,55),
...
}
您将在第一轮通过时构建此地图。要获取 2-3 时隙中的间隔数,只需返回 map[2].length (或任何等效项)。
显然,这是执行此操作的许多方法之一,并且需要更多上下文才能进入任何进一步的细节。
祝你好运