左滑 cell 实现置顶和删除

实现思路

=======

重写 UITableView 的代理方法,实现“置顶”和“删除”功能。(由于重写代理方法,SDK 父类中的“删除”功能失效)

示例代码

- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath
{
    RCConversationModel *model = self.conversationListDataSource[indexPath.row];
    
    NSString *topStr = @"置顶";
    if (model.isTop == YES) {
        topStr = @"取消置顶";
    }
    __weak typeof(self) __weakself = self;
    UITableViewRowAction *action0 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:topStr handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        BOOL isSuccess = [[RCIMClient sharedRCIMClient] setConversationToTop:model.conversationType targetId:model.targetId isTop:!model.isTop];
        [__weakself refreshUI:isSuccess];
    }];
    action0.backgroundColor = [UIColor orangeColor];
    
    UITableViewRowAction *action1 = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction *action, NSIndexPath *indexPath) {
        BOOL isSuccess = [[RCIMClient sharedRCIMClient] removeConversation:model.conversationType targetId:model.targetId];
        [__weakself refreshUI:isSuccess];
    }];
    return @[action1, action0];
}
- (void)refreshUI:(BOOL)isSuccess {
    __weak typeof(self) __weakself = self;
    if (isSuccess) {
        [__weakself refreshConversationTableViewIfNeeded];
    } else {
        NSLog(@"操作失败");
    }
}

效果图: