ios - Remove an item from a UICollectionView -


i have set of images showing in uicollectionview. when user taps on image, spawns uiactionsheet few options image. 1 of them id removing photo uicollectionview. when user selects remove button in uiactionsheet, pops alert view asking confirmation. if user selects yes, should remove photo.

my problem is, remove item uicollectionview, have pass indexpath deleteitemsatindexpaths event. since final confirmation granted in alert view's diddismisswithbuttonindex event, can't figure out way indexpath of selected image there pass deleteitemsatindexpaths event. how can this?

here's code:

- (void)actionsheet:(uiactionsheet *)actionsheet clickedbuttonatindex:(nsinteger)buttonindex {     switch (buttonindex) {         case 0:             deletephotoconfirmalert = [[uialertview alloc] initwithtitle:@"remove photo"                                                                  message:@"do want remove photo?"                                                                 delegate:self                                                        cancelbuttontitle:@"cancel"                                                        otherbuttontitles:nil, nil];             [deletephotoconfirmalert addbuttonwithtitle:@"yes"];             [deletephotoconfirmalert show];              break;         case 1:             nslog(@"to edit photo");             break;     } }  - (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {     if (alertview == deletephotoconfirmalert) {         if (buttonindex == 1) {             // permission delete button granted here.             // here deleteitemsatindexpaths event should called indexpath         }     } }  - (void)deleteitemsatindexpaths:(nsarray *)indexpaths {  } 

why not make use of [self.collectionview indexpathsforselecteditems]; . have done deleting multiple images @ time.

- (void)alertview:(uialertview *)alertview diddismisswithbuttonindex:(nsinteger)buttonindex {   if (alertview == deletephotoconfirmalert) {     if (buttonindex == 1) {         // permission delete button granted here.         nsarray *selecteditemsindexpaths = [self.collectionview indexpathsforselecteditems];         // delete items data source.         [self deleteitemsfromdatasourceatindexpaths:selecteditemsindexpaths];          // delete items collection view.         [self.collectionview deleteitemsatindexpaths:selecteditemsindexpaths];     }   } }  // method deleting selected images data source array -(void)deleteitemsfromdatasourceatindexpaths:(nsarray  *)itempaths {    nsmutableindexset *indexset = [nsmutableindexset indexset];    (nsindexpath *itempath  in itempaths) {      [indexset addindex:itempath.row];    }    [self.images removeobjectsatindexes:indexset]; // self.images data source } 

edit

-(void)prepareforsegue:(uistoryboardsegue *)segue sender:(id)sender {    nsarray *indexpaths = [self.collectionview indexpathsforselecteditems];    detailviewcontroller *dest = [segue destinationviewcontroller];    dest.imagename = [self.images objectatindex:[[indexpaths objectatindex:0] row]]; } 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -