1。编辑菜单:包含剪切,复制,粘贴。。。等
2。<UITableViewDelegate>
//长按某行时,是否显示编辑菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
//当可显示编辑菜单时,哪些操作选项可显示
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)) {
return YES; //只显示copy操作,其它不显示
}
return NO;
}
//对于编辑菜单中 显示的操作选项被用户选中时,对应的具体执行步骤
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender {
if (action == @selector(copy:)){
UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
UIPasteboard *pasteBoard = [UIPasteboardgeneralPasteboard]; //复制到粘贴板
[pasteBoard setString:cell.textLabel.text];
}
}