// 主要代碼 #warning iOS8 - #pragma mark 在滑動手勢刪除某一行的時候,顯示出更多的按鈕 - (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath { // 添加一個刪除按鈕 UITableViewRowAction *deleteRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了刪除"); // 1. 更新數據 [_allDataArray removeObjectAtIndex:indexPath.row]; // 2. 更新UI [tableView deleteRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationAutomatic]; }]; // 刪除一個置頂按鈕 UITableViewRowAction *topRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleDefault title:@"置頂"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了置頂"); // 1. 更新數據 [_allDataArray exchangeObjectAtIndex:indexPath.row withObjectAtIndex:0]; // 2. 更新UI NSIndexPath *firstIndexPath = [NSIndexPath indexPathForRow:0inSection:indexPath.section]; [tableView moveRowAtIndexPath:indexPathtoIndexPath:firstIndexPath]; }]; topRowAction.backgroundColor = [UIColor blueColor]; // 添加一個更多按鈕 UITableViewRowAction *moreRowAction = [UITableViewRowActionrowActionWithStyle:UITableViewRowActionStyleNormal title:@"更多"handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) { NSLog(@"點擊了更多"); [tableView reloadRowsAtIndexPaths:@[indexPath]withRowAnimation:UITableViewRowAnimationMiddle]; }]; moreRowAction.backgroundEffect = [UIBlurEffecteffectWithStyle:UIBlurEffectStyleDark]; // 將設置好的按鈕放到數組中返回 return @[deleteRowAction, topRowAction, moreRowAction]; }