У меня есть код, который удаляет объект из NSCollectionView, но он удаляет только один элемент. В NSArray («array») значение равно «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
Я имею в виду, что ему нужно удалить содержимое коллекции, которое является NSMutableArray. Но все это пишут. Это что-то с этим кодом. –
Вы производите NSString для NSNumber. Очень, очень нездоровый. – gnasher729