ios - Error SIGABRT while trying to delete multiple selected cells in UICollectionView: -
i trying delete series of selected images in uicollectionview
on clicking delete button. here 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 declarations , 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 click on delete button, signal abort exception on highlighted line below. suggestions?
int main(int argc, char *argv[]) { @autoreleasepool { **return uiapplicationmain(argc, argv, nil, nsstringfromclass([nmappdelegate class]));** //sigabrt } }
your for
loop structured incorrectly.
you repeatedly retrieving nsarray
reference using integer in delete calls.
you should retrieve selected index paths once , iterate on selected paths -
- (ibaction)deletevideos:(id)sender { if(deleteenabled){ if([selectedvideos count]>0){ nsarray *selectedindexpaths=self.memorymirrorsessioncollectionview.indexpathsforselecteditems; for(nsindexpath *indexpath in selectedindexpaths) { [videoimagesarray removeobjectatindex:indexpath.item]; [image_array removeobjectatindex: indexpath,item]; nslog(@"%d", indexpath.item); [self.memorymirrorsessioncollectionview deleteitemsatindexpaths:indexpath]; } } } }
Comments
Post a Comment