ios中tableviewcell允许长按出现剪切板

来源:互联网 发布:美国10月大非农数据 编辑:程序博客网 时间:2024/06/05 00:49
//允许长按菜单
 -(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath{
 return YES;
 }
 //允许每一个Action
 -(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
 NSLog(@"%@",NSStringFromSelector(action));
 return YES;
 }
 //对一个给定的行告诉代表执行复制或粘贴操作内容,
 -(BOOL)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender{
 Notification* temp = [[Notification alloc] init];
 if ([_notifications count]!= 0 && _notifications) {
 temp  = [_notifications objectAtIndex:indexPath.section];
 if (action==@selector(copy:)) {//如果操作为复制
 UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];//黏贴板
 [pasteBoard setString:temp.content];
 NSLog(@"%@",pasteBoard.string);//获得剪贴板的内容
 return YES;
 }
 
 }
 return NO;
 }

原创粉丝点击