UITableView 需要长按显示系统菜单

在实现系统提示菜单时,一般用户的行为是,长按给出系统提示菜单


下例子为长按弹出系统复制菜单,并给予实现

- (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:)) {

UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];

UIPasteboard *pasteBorad = [UIPasteboard generalPasteboard];

[pasteBorad setString:cell.textLabel.text];

}

}

你可能感兴趣的:(UITableView 需要长按显示系统菜单)