如何显示“复制”表格单元格的菜单? [英] How to show "Copy" menu for a table cell?

查看:225
本文介绍了如何显示“复制”表格单元格的菜单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我会添加选项以复制联系人应用中的表格中的选定单元格。

I would add the option to copy the selected cell in a table like in the contacts app.

我曾尝试关注有关Objective-C的这个问题并提出这些问题Swift中的方法:

I have tried to follow this question about Objective-C and impliment those methods in Swift:

override func tableView(tableView: UITableView, shouldShowMenuForRowAtIndexPath indexPath: NSIndexPath) -> Bool {
    return true
}

override func canPerformAction(action: Selector, withSender sender: AnyObject?) -> Bool {
    return (action == #selector(NSObject.copy(_:)))
}

然而,这是一个老问题,我无法使用 Swift 代码显示菜单。有人可以解释如何使用 shouldShowMenuForRowAtIndexPath 方法以及如何允许用户复制单元格。

However, that is an old question, and I can't get the menu to show up using Swift code. Could someone explain how the shouldShowMenuForRowAtIndexPath method is used and how to allow for a user to copy a cell.

推荐答案

您可以参考一个Objective-C示例,但您还没有完成它所说的内容去做!你的第二种方法是错误的方法。你想这样说:

You refer to an Objective-C example, but you have not done what it says to do! Your second method is the wrong method. You want to say this:

override func tableView(tableView: UITableView, canPerformAction action: Selector, 
    forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) 
    -> Bool {
        return action == #selector(copy(_:))
}

你还需要第三次覆盖:

override func tableView(tableView: UITableView, performAction action: Selector, 
    forRowAtIndexPath indexPath: NSIndexPath, withSender sender: AnyObject?) {
        // ...
}

这篇关于如何显示“复制”表格单元格的菜单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆