I am trying to delete a series of selected images in a UICollectionView
on clicking the Delete button. Here is my Delete Button action:
- (IBAction)deleteVideos:(id)sender {
if(deleteEnabled){
if([selectedVideos count]>0){
for(NSArray *indexPath in self.memoryMirrorSessionCollectionView.indexPathsForSelectedItems) {
[videoImagesArray removeObjectAtIndex:indexPath];
[image_array removeObjectAtIndex: indexPath];
NSLog(@"%@", indexPath);
[self.memoryMirrorSessionCollectionView deleteItemsAtIndexPaths:indexPath];
}
}
}
}
And these are my declarations and definitions:
@interface XVZUICollectionController(){
NSMutableArray *videoImagesArray;
BOOL selectEnabled;
NSMutableArray *selectedVideos;
BOOL deleteEnabled;
BOOL shareEnabled;
NSInteger *indexStack;
}
- (void)viewDidLoad {
image_array = [NSMutableArray arrayWithObjects: @"TestImage1.jpg", @"TestImage2.png", @"TestImage3.jpg", @"TestImage4.png",@"TestImage5.jpg", @"TestImage2.png",@"TestImage1.jpg", @"TestImage5.jpg", nil ];
videoImagesArray = [NSMutableArray arrayWithObjects: image_array, nil];
}
When I click on the delete button, i get a signal abort exception on the highlighted line below. Any suggestions?
int main(int argc, char *argv[])
{
@autoreleasepool {
**return UIApplicationMain(argc, argv, nil, NSStringFromClass([NMAppDelegate class]));** //SIGABRT
}
}
Your
for
loop is structured incorrectly.You are repeatedly retrieving an
NSArray
reference but then using this as an integer in your delete calls.You should retrieve the selected index paths once and then iterate over the selected paths -