gpt4 book ai didi

ios - 如何显示表格单元格的 "Copy"菜单?

转载 作者:搜寻专家 更新时间:2023-10-30 22:06:20 25 4
gpt4 key购买 nike

我会添加选项以复制表格中的选定单元格,就像在联系人应用中一样。

copy menu

我试着关注this question关于 Objective-C 并在 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 方法以及如何允许用户复制单元格。

最佳答案

你引用an Objective-C example ,但你没有按照它说的去做!你的第二种方法是错误的方法。你想这样说:

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?) {
// ...
}

关于ios - 如何显示表格单元格的 "Copy"菜单?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36241465/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com