1

This behaviour can be found in Contacts app.

If you long press a table row in a contact page, "copy" option popups on top of the row. How can I get this behaviour in my own table view cells.

4

1 回答 1

2

如果您使用的是 iOS 5.0 或更高版本,则可以使用默认行为:

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    if (action == @selector(copy:)) {
        return YES;
    }    
    return NO;
}

- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    if (action == @selector(copy:)) {
        [UIPasteboard generalPasteboard].string = @"test";
    }
}
于 2012-12-12T10:48:18.293 回答