我正在嘗試iCarousel
Multiple Carousel
示例。 在這裏,在我的數組,我和的NSMutableDictionary添加圖像:NSMutableArray索引混合起來
我有兩個:(myImages和myImages2在旋轉木馬我的兩個插槽在viewDidLoad中加載)
self.myImages = [NSMutableArray array];
for(int i = 0; i <= 10; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedPath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"myImages%d.png", i]];
if([[NSFileManager defaultManager] fileExistsAtPath:savedPath]){
NSMutableDictionary *container = [[NSMutableDictionary alloc] init];
[container setObject:[UIImage imageWithContentsOfFile:savedPath] forKey:@"image"];
[container setObject:[NSNumber numberWithInt:i] forKey:@"index"];
[images addObject:container];
[container release]; // if not using ARC
}
}
在我iCarousel
:
- (UIView *)carousel:(iCarousel *)carousel viewForItemAtIndex:(NSUInteger)index reusingView:(UIView *)view
{
if (carousel == carousel1)
{
NSDictionary *obj = [items1 objectAtIndex:index];
view = [[UIImageView alloc] initWithImage:[obj objectForKey:@"items1"]];
view.tag = index;
}else
{
NSDictionary *obj = [items2 objectAtIndex:index];
view = [[UIImageView alloc] initWithImage:[obj objectForKey:@"items2"]];
view.tag = index;
}
return view;
}
在另一視圖中,這些陣列也被加載,則用戶有機會選擇一個圖像進行比較,以與,
當用戶選擇一個與它的標籤等價的int圖像傳遞到我的兩個Carousel所在的位置。
這是我如何對它們進行比較:
NSInteger image = [prefs integerForKey:@"image"];
NSInteger image1 = [prefs integerForKey:@"image2"];
if (image == [(UIImageView*)[self.carousel1 currentItemView] tag] || image2= [(UIImageView*)[self.carousel2 currentItemView] tag] ||) {
我刪除索引是這樣的:
NSInteger index = carousel1.currentItemIndex;
[carousel1 removeItemAtIndex:index animated:YES];
[items1 removeObjectAtIndex:index];
我想我刪除它錯了,因爲該指數的arent更新,是什麼我想保持其索引不調整像這樣的圖像在這裏:
看着這篇文章和你的其他文章,我看不到問題。在標準動態數組中,當一個項目被刪除時,所有其他項目的索引都會被更新。在這種情況下,你永遠不應該有這樣一種情況,即你從列表0,1,2,3中刪除了項目1,並以0,2,3結束。正確的結果數組是0,1,2! – trumpetlicks
但我真的有問題比較採摘imageView(標籤視圖)與我的carouselVIew,所以我認爲我的數組有問題,我真的不知道如何解決它。 – Bazinga
這真的是你的代碼,因爲你有一個額外的|| (或)在您的比較結尾處if如果 – trumpetlicks