iOS實現(xiàn)UITableView左滑刪除復(fù)制即用功能
更新時間:2017年09月20日 11:16:21 作者:Fantasy_Jun
這篇文章主要介紹了iOS實現(xiàn)UITableView左滑刪除復(fù)制即用功能,在項目開發(fā)中經(jīng)常會用到這樣的需求,下面小編把實現(xiàn)代碼分享給大家,需要的朋友可以參考下
開發(fā)項目時候需要用到tableview左滑刪除,就研究了一下,話不多說直接上代碼
//設(shè)Cell可編輯
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//設(shè)置刪除按鈕
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
//進(jìn)入編輯(刪除)模式
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
//出現(xiàn)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) {
//需要先刪除數(shù)據(jù)源中對應(yīng)數(shù)據(jù),不然執(zhí)行下一步會崩潰
[reconnaissanceListArr removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}]];
[self presentViewController:alertController animated:YES completion:nil];
}
}
//修改編輯按鈕文字
-(NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"刪除";
}
//設(shè)置進(jìn)入編輯狀態(tài)時,Cell不會縮進(jìn)
- (BOOL)tableView: (UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
return NO;
}
總結(jié)
以上所述是小編給大家介紹的iOS實現(xiàn)UITableView左滑刪除復(fù)制即用功能,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
您可能感興趣的文章:
相關(guān)文章
詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題
這篇文章主要介紹了詳解iOS 關(guān)于字體根據(jù)不同屏幕尺寸等比適配的問題,具有一定的參考價值,感興趣的小伙伴們可以參考一下2017-06-06
iOS中UILabel實現(xiàn)長按復(fù)制功能實例代碼
在iOS開發(fā)過程中,有時候會用到UILabel展示的內(nèi)容,那么就設(shè)計到點擊UILabel復(fù)制它上面展示的內(nèi)容的功能,也就是Label長按復(fù)制功能,下面這篇文章主要給大家介紹了關(guān)于在iOS中UILabel實現(xiàn)長按復(fù)制功能的相關(guān)資料,需要的朋友可以參考借鑒,下面來一起看看吧。2017-10-10
iOS App開發(fā)中導(dǎo)航欄的創(chuàng)建及基本屬性設(shè)置教程
這篇文章主要介紹了iOS App開發(fā)中導(dǎo)航欄的創(chuàng)建及基本屬性設(shè)置教程,即用UINavigationController來編寫navigation,示例代碼為Objective-C語言,需要的朋友可以參考下2016-02-02
實例解析iOS中音樂播放器應(yīng)用開發(fā)的基本要點
這篇文章主要介紹了iOS開發(fā)中制作一個簡單的音樂播放器的基本要點解析,代碼基于傳統(tǒng)的Objective-C,需要的朋友可以參考下2016-01-01
iOS實現(xiàn)應(yīng)用內(nèi)切換本地化語言的方法實例
網(wǎng)絡(luò)上關(guān)于iOS國際化的文章很多,但基本上都是基于跟隨系統(tǒng)語言的國際化,而這篇文章主要給大家介紹了關(guān)于利用iOS實現(xiàn)應(yīng)用內(nèi)切換本地化語言的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考。2017-12-12

