需要在uitableviewcell上同时显示“复制”和“删除”弹出窗口

时间:2016-05-10 08:17:50

标签: ios xcode uitableview

我正在尝试弹出包含2个选项的弹出窗口(复制和删除),但目前代码只显示其中的复制,请查看下面的代码。

- (BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}
- (BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    return (action == @selector(copy:)) || (action == @selector(delete:));
}
- (void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
    if (action == @selector(copy:))
    {
        UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
        UIPasteboard *pasteBoard = [UIPasteboard generalPasteboard];
        [pasteBoard setString:cell.textLabel.text];
    }
    if (action == @selector(delete:))
    {
        NSLog(@"delete pressed!");
    }

}

2 个答案:

答案 0 :(得分:0)

我已经使用这个库来实现可切换的按钮,它支持各种转换和可扩展按钮。

https://github.com/MortimerGoro/MGSwipeTableCell

这个库与创建UITableViewCell的所有不同方法兼容,并且在最新版本的iOS上也可以正常工作。

enter image description here

P.S。我建议你提供这样的用户界面。

答案 1 :(得分:0)

尝试替换

return (action == @selector(copy:)) || (action == @selector(delete:));

return (action == @selector(copy:)) && (action == @selector(delete:));

希望这会有所帮助:)