gpt4 book ai didi

iphone - iCarousel 的索引

转载 作者:行者123 更新时间:2023-11-29 04:37:22 24 4
gpt4 key购买 nike

如何确定轮播的索引?或者加载到其中的数组索引?我已经从 NSDocumentDirectory 加载了图像。

self.myImages = [NSMutableArray new];  
for(int i = 1; i <= 30; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];

NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]];
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
NSLog(@"file exists");
}

}

并将它们添加到 iCarousel View 中:

- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[myImages objectAtIndex:index]];
return view;
}

最佳答案

如果我没有误解你的问题,你可以尝试使用 UIView 的 tag 属性进行比较。例如:

viewForItemAtIndex中:

- (UIView *)carousel:(iCarousel *)_carousel viewForItemAtIndex:(NSUInteger)index  reusingView:(UIView *)view
{
view = [[UIImageView alloc] initWithImage:[myImages objectAtIndex:index]];
view.tag = index;
return view;
}

currentItemView与另一个图像进行比较

If (int == [(UIImageView*)[self.carousel currentItemView] tag]) { 
//do something
}

关于iphone - iCarousel 的索引,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10892465/

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