2012-07-04 27 views
0

當刪除iCarousel來看,是這樣的:NSMutableArray的指標難度

[carousel removeItemAtIndex:index animated:YES];

如何保持/保留刪除的意見/指數甚至會不同viewController?因爲根據我的經驗,它返回它的視圖,或將刪除的索引放入數組中?這可能嗎?

已經嘗試添加數組到app delegate,但仍然沒有運氣。 還沒有試過singleton呢。但有沒有其他方法,謝謝你的幫助。

+0

刪除之前將這些索引保存在數組中。 – Tendulkar

+0

@tendulkar,怎麼樣? – Bazinga

回答

0

是的,您可以在AppDelegate中創建一個數組並將索引放入該數組中。但之前,您應該以這種方式從NSInteger(int)創建NSNumber對象:

// This line should be in your delegate 
NSMutableArray *indexesArray = [[NSMutableArray alloc] init]; 

// In your controller: 
NSInteger index = 1; // Use your index instead 
NSNumber *indexObject = [NSNumber numberWithInt:index]; 
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate]; 
[appDelegate.indexesArray addObject:indexObject]; 

同樣是對於視圖。您也可以將UIView對象存儲在NSMutableArray中。

UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)]; 
[appDelegate.viewsArray addObject:view]; 
+0

我想要的是甚至當我刪除一個索引時,即使我進入另一個視圖,它也會被保留下來? – Bazinga