簡單模仿QQ置頂,刪除,關注實現代碼

  • 置頂
UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"置頂" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
        // KVC 修改模型
        XMGWine *wine = self.wineArray[indexPath.row];
        // 先刪除,后插入,不能把兩者調換順序
        // 先刪除不要理解為刪除了模型數據,而是理解為去掉一根強引用的線
        [self.wineArray removeObject:wine];
        [self.wineArray insertObject:wine atIndex:0];
        // 刷新表格
        [self.tableView reloadData];
    }];
  • 刪除
UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDestructive title:@"刪除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

        // 修改模型
        [self.wineArray removeObjectAtIndex:indexPath.row];

        // 刷新表格
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationBottom];
    }];
  • 退出編輯模式
UITableViewRowAction *action = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"關注" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {

//        [self.tableView reloadData];
//        [self.tableView reloadRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationRight];
        // 退出編輯模式
        self.tableView.editing = NO;
    }];
  • 關注欠缺
最后編輯于
?著作權歸作者所有,轉載或內容合作請聯系作者
平臺聲明:文章內容(如有圖片或視頻亦包括在內)由作者上傳并發布,文章內容僅代表作者本人觀點,簡書系信息發布平臺,僅提供信息存儲服務。

推薦閱讀更多精彩內容