我的 UITableViewController 有一个问题:表格 View 出现了,但 didDeselectRowAt 只会在触摸单元格时每隔一秒调用一次。有人看到这段代码有问题吗?
import UIKit
import MediaPlayer
class LibraryTableViewController: UITableViewController{
let mediaItems = MPMediaQuery.songs().items
override func viewDidLoad() {
super.viewDidLoad()
self.tableView.register(UITableViewCell.self, forCellReuseIdentifier: "cell")
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return mediaItems!.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath)
cell.textLabel?.text = mediaItems?[indexPath.row].title
return cell
}
override func tableView(_ tableView: UITableView, didDeselectRowAt indexPath: IndexPath) {
print("table item selected")
OperationQueue.main.addOperation{
self.performSegue(withIdentifier: "showPlayer", sender: self)
}
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showPlayer"{
let playerVC = segue.destination as! PlayerViewController
let indexPath = tableView.indexPathForSelectedRow!
playerVC.mediaItem = mediaItems?[indexPath.row]
}
}
}
最佳答案
将 didDeselectRowAt 更改为 didSelectRowAt
关于ios - UITableView : Action only works every second time 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42415343/