我使我的老虎機應用程序使用iCarousel
,我的iCarousel
包含圖像來自NSDocumentDirectory
此圖像來自我的ImagePicker
。所以這裏是我的應用程序如何工作,當用戶按下按鈕iCarousel
旋轉。 停止時,顯示該項目3秒鐘,然後將其刪除。NSMutableArray索引刪除
我的問題是當我去另一個視圖時,刪除的索引/項目再次出現。即使我看到不同的觀點,如何保持我的陣列。刪除的索引/項目將不會顯示,直到重新啓動應用程序爲止,例如保存數組。謝謝您的幫助。
//我的數組
- (void)viewDidLoad
{
self.images = [NSMutableArray new];
for(int i = 0; i <= 100; i++)
{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDir = [paths objectAtIndex:0];
NSString *savedImagePath = [documentsDir stringByAppendingPathComponent:[NSString stringWithFormat:@"images%d.png", i]];
if([[NSFileManager defaultManager] fileExistsAtPath:savedImagePath]){
[images addObject:[UIImage imageWithContentsOfFile:savedImagePath]];
}
}
}
- (void)viewWillAppear:(BOOL)animated {
spinButton = [UIButton buttonWithType:UIButtonTypeCustom];
[spinButton addTarget:self action:@selector(spin) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:spinButton];
}
- (void) carouselDidEndScrollingAnimation:(iCarousel *)carousel{
[NSTimer scheduledTimerWithTimeInterval:0.56 //this arranges the duration of the scroll
target:self
selector:@selector(deleteItem)
userInfo:nil
repeats:NO];
}
//自旋和刪除方法
- (void)spin {
[carousel scrollByNumberOfItems:-35 duration:10.7550f];
}
-(void) deleteItem {
//Removes the object chosen
NSInteger index = carousel.currentItemIndex;
[carousel removeItemAtIndex:index animated:YES];
[images removeObjectAtIndex:index];
}
我需要的是,當索引/項目被刪除,不會被暫時就算我出去其他意見。只有在應用程序關閉並重新打開後,視圖纔會重新啓動。
您在哪裏創建這個數組,即在哪個方法中以及何時從數組中刪除元素? – rishi
已編輯它,請看看。 – Bazinga
如果您不是每次都創建視圖,則需要在viewWillAppear中重現數組。否則,您只能爲這兩個視圖使用一個數組,並且可以在應用程序委託中定義該數組。更簡單的方法:) – DivineDesert