2012-06-05 31 views
0

如何確定傳送帶的索引?或者在它的數組索引中加載?我從NSDocumentDirectory加載了我的圖像。iCarousel的索引

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觀點:

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

回答

1

如果我沒有誤解你的問題,你可以嘗試使用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 
} 
+0

非常感謝。 – Bazinga

0

凡(代碼),你需要旋轉木馬的指數?當您將圖像添加到傳送帶(在viewForItemAtIndex:中)時,以及當您點擊傳送帶時(在didSelectItemAtIndex:中),您會知道它。

此外,您可以使用傳送帶的currentItemIndex屬性。

+0

我試着將其與其他圖像,所以我採取賦值或東西的數組。例如:'if(int == carousel index/integer/value where it stop){// do something} ....' – Bazinga