在UITableViewCell中显示快捷菜单
- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath { return YES;}- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender { return YES;}- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender { if (action == @selector(copy:)) { [UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row]; } if (action == @selector(cut:)) { [UIPasteboard generalPasteboard].string = [dataArray objectAtIndex:indexPath.row]; [dataArray replaceObjectAtIndex:indexPath.row withObject:@""]; [tbl reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; } if (action == @selector(paste:)) { NSString *pasteString = [UIPasteboard generalPasteboard].string; NSString *tmpString = [NSString stringWithFormat:@"%@ %@", [dataArray objectAtIndex:indexPath.row], pasteString]; [dataArray replaceObjectAtIndex:indexPath.row withObject:tmpString]; [tbl reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationNone]; }}
?
可以支持的菜单列表如下:
cut:
copy:
select:
selectAll:
paste:
delete:
_promptForReplace:
_showTextStyleOptions:
_define:
_addShortcut:
_accessibilitySpeak:
_accessibilitySpeakLanguageSelection:
_accessibilityPauseSpeaking:
makeTextWritingDirectionRightToLeft:
makeTextWritingDirectionLeftToRight:
