相信每一個IOS開發者都知道uitableview,其實uitableview的左幻燈片刪除功能是非常酷,下面由武林技術頻道小編來告訴大家iOS實現UITableView左滑刪除復制即用功能。
//設Cell可編輯- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{ return YES;}//設置刪除按鈕-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath{ return UITableViewCellEditingStyleDelete;}//進入編輯(刪除)模式-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{ //出現alterView隱藏刪除按鈕 [tableView setEditing:NO animated:YES]; if (editingStyle == UITableViewCellEditingStyleDelete) { UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"你確定刪除該消息?" preferredStyle:UIAlertControllerStyleAlert]; [alertController addAction:[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil]]; [alertController addAction:[UIAlertAction actionWithTitle:@"確定" style:UIAlertActionStyleDestructive handler:^(UIAlertAction * _Nonnull action) { //需要先刪除數據源中對應數據,不然執行下一步會崩潰 [reconnaissanceListArr removeObjectAtIndex:indexPath.row]; [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic]; }]]; [self presentViewController:alertController animated:YES completion:nil]; }}//修改編輯按鈕文字-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath{ return @"刪除";}//設置進入編輯狀態時,Cell不會縮進- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath{ return NO;}好了,以上就是iOS實現UITableView左滑刪除復制即用功能,互聯網上還有很多學習知識的平臺,希望想學習的朋友可以收藏武林技術頻道,學習到更多的知識。
新聞熱點
疑難解答