我有一個代碼從NSCollectionView中刪除一個對象,但它只能刪除一個項目。在NSArray(「數組」)中,值是「2 4」,它返回2,4。但是當我運行代碼時,它只刪除「2」而不是「4」。索引從NSArray中刪除對象
日誌:
Click here for the image of the NSLOG.
守則
NSString* LibraryPath = [NSSearchPathForDirectoriesInDomains(NSLibraryDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *plistPathSMSettings = [LibraryPath stringByAppendingString:stormarManagerSettingsPlistPath];
NSString *betasDef = [SMInAppCommunicationDEF stringByAppendingString:@"BETA App Id"];
NSString *indexOfApp = [Functions readDataFromPlist:plistPathSMSettings ForKey:betasDef];
if (!(indexOfApp == nil)) {
NSArray * array = [indexOfApp componentsSeparatedByString:@" "];
NSLog(@"Array: ", array);
int currentValue = 0;
for (int i = 0; i < [array count]; i++)
{
currentValue = [(NSNumber *)[array objectAtIndex:i] intValue];
NSLog(@"currentValue: %d", currentValue); // EXE_BAD_ACCESS
NSLog(@"x: %d", i);
[self.content removeObjectAtIndex:(currentValue)];
[self.collectionView setContent:self.content];
[self.collectionView reloadData];
NSLog(@"next: %d", currentValue); // EXE_BAD_ACCESS
}
}
else if (indexOfApp == nil) {
[self.collectionView setContent:self.content];
[self.collectionView reloadData];
}
'NSArray'是不變的,所以你不能刪除任何東西。 – Droppy
我的意思是它需要從collectionview內容中刪除,這是NSMutableArray。但是這都寫。這是這個代碼的東西。 –
您正在將NSString強制轉換爲NSNumber。非常非常不健康。 – gnasher729