ios开发怎么用代码控制手滑删除tableview
1个回答
展开全部
您好,您的问题,问的没有让我太明白,您的意思是,例如QQ会话列表的那种cell左滑删除当前cell吗?如果是,那么看如下代码:(若不是,请追问,谢谢)
//置顶,标为已读,删除
- (nullable NSArray<UITableViewRowAction *> *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(nonnull NSIndexPath *)indexPath {
RCConversation *currentCon = _conversationList[indexPath.row];
UITableViewRowAction *deleteAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"删除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[_conversationList removeObject:currentCon];
[self shouldNowNoMessageConversionPicShow];
[tableView reloadData];
[[RCIMClient sharedRCIMClient] removeConversation:currentCon.conversationType targetId:currentCon.targetId];
}];
UITableViewRowAction *hadReadAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:@"标为已读" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
((ChatListCell *)[_tableView cellForRowAtIndexPath:indexPath]).redDot.text = @"0";
[tableView reloadData];
[[RCIMClient sharedRCIMClient] clearMessagesUnreadStatus:currentCon.conversationType targetId:currentCon.targetId];
}];
BOOL isTop = currentCon.isTop;
UITableViewRowAction *putTopAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleNormal title:isTop?@"取消置顶":@"置顶" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
if (!isTop) {
[_conversationList removeObject:currentCon];
[_conversationList insertObject:currentCon atIndex:0];
}
currentCon.isTop = !currentCon.isTop;
[tableView reloadData];
[[RCIMClient sharedRCIMClient] setConversationToTop:currentCon.conversationType targetId:currentCon.targetId isTop:!isTop];
}];
hadReadAction.backgroundColor = [UIColor orangeColor];
return @[deleteAction,hadReadAction,putTopAction];
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询