試圖從NSMutableArray
中刪除對象,下面是如何加入數組。從陣列中刪除對象
sectionInfo = [self.collectionView indexPathsForSelectedItems];
如何試圖刪除
[sectionInfo removeAllObjects];
我得到的錯誤是無法識別選擇發送到實例0x169cfb70。 我認爲這是因爲我沒有添加項目數組屁股addObject:
但這不是我的要求。那麼,如何管理這個。
試圖從NSMutableArray
中刪除對象,下面是如何加入數組。從陣列中刪除對象
sectionInfo = [self.collectionView indexPathsForSelectedItems];
如何試圖刪除
[sectionInfo removeAllObjects];
我得到的錯誤是無法識別選擇發送到實例0x169cfb70。 我認爲這是因爲我沒有添加項目數組屁股addObject:
但這不是我的要求。那麼,如何管理這個。
的indexPathsForSelectedItems
返回一個不可改變的NSArray
,無論sectionInfo
如何申報。從理論上講,你可以這樣做:
sectionInfo = [[self.collectionView indexPathsForSelectedItems] mutableCopy];
或者,如果你只是想重置sectionInfo
,你可以離開的單獨sectionInfo
的聲明,但隨後而不是,你可以簡單地說:
sectionInfo = nil;
或創建一個新數組:
sectionInfo = [NSMutableArray array];
我猜它歸結爲,爲什麼你想從sectionInfo
刪除對象,而ŧ韓剛剛重置它。
問題是-[UICollectionView indexPathsForSelectedItems]
不返回NSMutableArray
。你想試圖修改它之前將它轉換成一個NSMutableArray
:
sectionInfo = [NSMutableArray arrayWithArray: [self.collectionView indexPathsForSelectedItems]];
充分利用indexPathsForSelectedItems
的可變副本。因爲indexPathsForSelectedItems
返回NSArray
而不是NSMutableArray
。 NSArray
沒有方法。
sectionInfo = [[self.collectionView indexPathsForSelectedItems]mutableCopy];
部分信息是一個NSMutable數組? –