B2F*_*2Fq 3 xcode copy uitableview ios swift
我在UITableViewCell中向左/向右滑动?
我该如何做才能复制所选单元格中的数据?
我尝试使用它:
let cell = self.table.cellForRow(at: indexPath)
UIPasteboard.general.string = cell?.detailTextLabel?.text
Run Code Online (Sandbox Code Playgroud)
但是应用程序崩溃
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell: UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cell")!
cell.textLabel?.text = myData[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView,leadingSwipeActionsConfigurationForRowAt indexPath: IndexPath) -> UISwipeActionsConfiguration?{
let closeAction = UIContextualAction(style: .normal, title: "Close", handler: { (ac:UIContextualAction, view:UIView, success:(Bool) -> Void) in
print("Copy")
//let cell = self.table.cellForRow(at: indexPath)
//UIPasteboard.general.string = cell?.detailTextLabel?.text
success(true)
})
closeAction.title = "Copy"
closeAction.backgroundColor = .purple
return UISwipeActionsConfiguration(actions: [closeAction])
}
Run Code Online (Sandbox Code Playgroud)
更换:
let cell = self.table.cellForRow(at: indexPath)
UIPasteboard.general.string = cell?.detailTextLabel?.text
Run Code Online (Sandbox Code Playgroud)
带有:
let cell = tableView.cellForRow(at: indexPath)
UIPasteboard.general.string = cell?.textLabel?.text
Run Code Online (Sandbox Code Playgroud)
因为您正在使用tableViewin cellForRowAt方法。所以我table用tableView和在第二行替换detailTextLabel为textLabel。
这应该工作。
| 归档时间: |
|
| 查看次数: |
971 次 |
| 最近记录: |