我遇到了这个小问题,我已经实现了执行复制弹出窗口以显示用户何时复制表格 View 单元格上的项目。但是,出于某种原因,它没有显示复制弹出窗口。请看看我的代码,看看我做错了什么。
这是代码:
func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return action == #selector(copy(_:))
}
这是我的完整代码
import UIKit
import CoreLocation
class PlaceDetailViewController: BaseViewController, UITableViewDataSource, UITableViewDelegate {
@IBOutlet weak var tableView: UITableView!
@IBOutlet weak var headerView: PlaceDetailHeaderView!
var annotation: ARAnnotation?
var place: Place!
var nearMeIndexSelected = NearMeIndexTitle()
override func viewDidLoad() {
super.viewDidLoad()
if #available(iOS 11.0, *) {
navigationItem.largeTitleDisplayMode = .never
} else {
// Fallback on earlier versions
}
if self.place != nil {
self.title = place.placeName
self.tableView.delegate = self
self.tableView.dataSource = self
tableView.separatorStyle = .none
self.loadDetailInfo()
print("Place is not nil")
} else {
print("Place is nil")
}
// Configure header view
headerView.nameLabel.text = place?.placeName
headerView.headerImageView.image = UIImage(named: "blurimg.jpg")
}
func tableView(_ tableView: UITableView, canPerformAction action: Selector, forRowAt indexPath: IndexPath, withSender sender: Any?) -> Bool {
return action == #selector(copy(_:))
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 3
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
switch indexPath.row {
case 0:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PlaceDetailIconTextCell.self), for: indexPath) as! PlaceDetailIconTextCell
cell.iconImageView.image = UIImage(named: "phone")
cell.shortTextLabel.text = place?.phoneNumber
return cell
case 1:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PlaceDetailIconTextCell.self), for: indexPath) as! PlaceDetailIconTextCell
cell.iconImageView.image = UIImage(named: "map")
cell.shortTextLabel.text = place?.address
return cell
case 2:
let cell = tableView.dequeueReusableCell(withIdentifier: String(describing: PlaceDetailIconTextCell.self), for: indexPath) as! PlaceDetailIconTextCell
cell.iconImageView.image = UIImage(named: "web")
cell.shortTextLabel.text = place?.website
return cell
default:
fatalError("Failed to instantiate the table view cell for detail view controller")
}
}
}
最佳答案
如canPerformAction
方法的文档所示,您需要实现shouldShowMenuForRowAt
方法。
func tableView(_ tableView: UITableView, shouldShowMenuForRowAt indexPath: IndexPath) -> Bool {
return true
}
只有在实现并返回 true
时才会调用 canPerformAction
。
关于ios - "copy"选项不显示 UITableView 行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48244295/