#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];
}
}
}
TableViewCell实现长按复制功能
最新推荐文章于 2022-12-26 11:23:19 发布
