左滑出現(xiàn)刪除按鈕
- 需要實(shí)現(xiàn)tableView的代理方法
/**
* 只要實(shí)現(xiàn)了這個(gè)方法和媳,左滑出現(xiàn)Delete按鈕的功能就有了
* 點(diǎn)擊了“左滑出現(xiàn)的Delete按鈕”會(huì)調(diào)用這個(gè)方法
*/
//IOS9前自定義左滑多個(gè)按鈕需實(shí)現(xiàn)此方法
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
// 刪除模型
[self.wineArray removeObjectAtIndex:indexPath.row];
// 刷新
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationLeft];
}
/**
* 修改Delete按鈕文字為“刪除”
*/
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"刪除";
}
左滑出現(xiàn)N個(gè)按鈕
- 需要實(shí)現(xiàn)tableView的代理方法
/**
* 只要實(shí)現(xiàn)了這個(gè)方法盈厘,左滑出現(xiàn)按鈕的功能就有了
(一旦左滑出現(xiàn)了N個(gè)按鈕,tableView就進(jìn)入了編輯模式, tableView.editing = YES)
*/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
}
/**
* 左滑cell時(shí)出現(xiàn)什么按鈕
*/
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"關(guān)注" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
NSLog(@"點(diǎn)擊了關(guān)注");
// 收回左滑出現(xiàn)的按鈕(退出編輯模式)
tableView.editing = NO;
}];
UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
[self.wineArray removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
}];
return @[action1, action0];
}
// self.tabelView.editing = YES;
[self.tableView setEditing:YES animated:YES];
// 默認(rèn)情況下息楔,進(jìn)入編輯模式時(shí),左邊會(huì)出現(xiàn)一排紅色的“減號(hào)”按鈕
// 編輯模式的時(shí)候可以多選
self.tableView.allowsMultipleSelectionDuringEditing = YES;
// 進(jìn)入編輯模式
[self.tableView setEditing:YES animated:YES];
// 獲得選中的所有行
self.tableView.indexPathsForSelectedRows;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者