TableViewCell实现长按复制功能

来源:互联网 发布:pony粉饼知乎 编辑:程序博客网 时间:2024/06/08 04:55
#pragma mark - 长按复制cell 相关代理方法// 允许长按菜单- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{    if (indexPath.section == 4 && indexPath.row == 1) {        return YES;    }else{        return NO;    }}// 点击指定的cell 出现Menu菜单- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{    if (indexPath.section == 4 && indexPath.row == 1) {        if (action == @selector(copy:)) {            return YES;        }    }    return NO;}// 执行复制操作- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{    if (indexPath.section == 4 && indexPath.row == 1) {        if (action == @selector(copy:)) {            UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];            UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard]; // 粘贴板            [pasteBoard setString:cell.detailTextLabel.text];        }    }}
原创粉丝点击