gpt4 book ai didi

ios - 如何在循环内增加索引并停止枚举?

转载 作者:行者123 更新时间:2023-11-29 01:08:35 24 4
gpt4 key购买 nike

我遇到了需要循环的情况,但下面的代码仅返回最后一个索引值。我需要它返回下一个值并停止枚举。为了更好地解释,假设我有数字 0-10,当按下按钮时我需要索引增加 1。现在假设我一直按此按钮,直到索引达到 10,下次按时,索引需要返回到零(也称为循环。)

任何帮助将不胜感激,我绝对会接受最佳答案。

提前致谢!

//grabs current index in a scrollview
long long currentSelectedIndex = [preview.swipeView currentIndex];
long long totalNumberOfAvailableSlots = [preview.swipeView indexTotal]; //index total is never an absolute value

@autoreleasepool {
//currentSelectedIndex is supposed/always to be zero on first run
for (int i; = (int)currentSelectedIndex; i <= totalNumberOfAvailableSlots; i++){
NSLog(@"loop: %d", i);
if (i == totalNumberOfAvailableSlots){
i = -1;
[preview.swipeView scrollToIndex:i]; //this will cause [preview.swipeView currentIndex] to be updated with "i" value.
}
}
}

最佳答案

根据我的评论,您似乎想要的行为是自动滑动浏览 swipeView 的内容。

制作一个定时器调用swipeToNext方法:

myTimer = [NSTimer scheduledTimerWithTimeInterval: target:self selector:@selector(swipeToNext) userInfo:nil repeats:YES];

然后处理滑动:

- (void)swipeToNext {
if ([preview.swipeView currentIndex] < [preview.swipeView indexTotal]) {
//Can swipe forward
[preview.swipeView scrollToIndex:[preview.swipeView currentIndex]+1];
} else {
//At last index. Need to go to first.
[preview.swipeView scrollToIndex:0];
}
}

关于ios - 如何在循环内增加索引并停止枚举?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36046500/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com