//允许Menu菜单
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//每个cell都可以点击出现Menu菜单
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
// return YES; // 全部显示
//显示 copy
- if (action == @selector(cut:)){
- return NO;
- } else if(action == @selector(copy:)){
- return YES;
- }
- else if(action == @selector(paste:)){
- return NO;
- }
- else if(action == @selector(select:)){
- return NO;
- }
- else if(action == @selector(selectAll:)){
- return NO;
- } else {
- return [super canPerformAction:action withSender:sender];
- }
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
if (action ==@selector(copy:)) {
[UIPasteboard generalPasteboard].string = [arrayValueobjectAtIndex:indexPath.row];
}
if (action ==@selector(cut:)) {
[UIPasteboard generalPasteboard].string = [arrayValueobjectAtIndex:indexPath.row];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject:@""];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
if (action ==@selector(paste:)) {
NSString *pasteString = [UIPasteboard generalPasteboard].string;
NSString *tmpString = [NSString stringWithFormat:@"%@%@",[arrayValue objectAtIndex:indexPath.row],pasteString];
[arrayValue replaceObjectAtIndex:indexPath.rowwithObject:tmpString];
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]withRowAnimation:UITableViewRowAnimationNone];
}
}
效果如下图