iphone - Get the indexpath of the selected cell -
when user taps on default delete
button in uitableview
edit mode,the user should alertview , if hits delete again in alertview row should deleted.initially have done following code without alertview , worked fine.
[[self categoriesarray]removeobjectatindex:[indexpath row]]; nsarray *indexpathstoremove = [nsarray arraywithobject:indexpath]; [self.tableview deleterowsatindexpaths:indexpathstoremove withrowanimation:uitableviewrowanimationleft]; [self.categoriesarray writetofile:[self datafilepath] atomically:yes];
but now,as have use same code in alertview delegate method.i dont know how [indexpath row]
set indexpath uialertview
tag , delegate.
- (void)tableview:(uitableview *)tableview commiteditingstyle:(uitableviewcelleditingstyle)editingstyle forrowatindexpath:(nsindexpath *)indexpath // indexpath here { if (editingstyle == uitableviewcelleditingstyledelete) { uialertview * alertview = [[uialertview alloc]initwithtitle:@"alert" message:@"are sure want delete" delegate:self cancelbuttontitle:@"cancel" otherbuttontitles:@"delete", nil]; [alertview settag:indexpath.row]; // assigning here. [alertview show]; } } // uialertview delegate - (void)alertview:(uialertview *)alertview clickedbuttonatindex:(nsinteger)buttonindex { nslog(@"%d",alertview.tag); // indexpath here **edited:** nsindexpath * path = [nsindexpath indexpathforrow:alertview.tag insection:0]; [[self categoriesarray]removeobjectatindex:[path row]]; nsarray * indexpathstoremove = [nsarray arraywithobject:path]; [self.tableview deleterowsatindexpaths:indexpathstoremove withrowanimation:uitableviewrowanimationleft]; [self.categoriesarray writetofile:[self datafilepath] atomically:yes]; }
Comments
Post a Comment