【问题标题】:Issue with UITableView: Action only works every second timeUITableView 的问题:操作仅每两次有效
【发布时间】:2017-07-13 21:50:57
【问题描述】:

我遇到了 UITableViewController 的问题:表格视图显示了,但在触摸单元格时,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]    
        }
    }     
}

【问题讨论】:

    标签: ios uitableview swift3


    【解决方案1】:

    didDeselectRowAt 更改为 didSelectRowAt

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2020-04-19
    • 2023-02-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多