ios - How to delete the tableview cell without pressing delete button? -
- (nsarray *)tableview:(uitableview *)tableview editactionsforrowatindexpath:(nsindexpath *)indexpath { uitableviewcell *cell = [tableview1 cellforrowatindexpath:indexpath]; uitableviewrowaction *flagaction = [uitableviewrowaction rowactionwithstyle:uitableviewrowactionstyledefault title:@"delete" handler:^(uitableviewrowaction *action, nsindexpath *indexpath) { [tabledata removeobjectatindex:indexpath.row]; nslog(@"indexpath %ld",indexpath.row); [tableview deleterowsatindexpaths:@[indexpath] withrowanimation:uitableviewrowanimationautomatic]; }]; return @[ flagaction]; }
you can add swipe gesture table , delete row shown following.
- (void)viewdidload { uiswipegesturerecognizer *gesturedeleterow = [[uiswipegesturerecognizer alloc] initwithtarget:self action:@selector(cellswipe:)]; gesturedeleterow.direction = uiswipegesturerecognizerdirectionright; [tableview addgesturerecognizer:gesturedeleterow]; } //swipe handler method -(void)cellswipe:(uiswipegesturerecognizer *)gesture { cgpoint location = [gesture locationinview:tableview]; nsindexpath *swipedindexpath = [tableview indexpathforrowatpoint:location]; //delete row… [array removeobjectatindex: swipedindexpath.row]; [tableview deleterowsatindexpaths:[nsarray arraywithobjects:swipedindexpath, nil] withrowanimation:uitableviewrowanimationleft]; }
Comments
Post a Comment