ios - TableViewCell 到 ViewController - Swift

标签 ios swift xcode uitableview viewcontroller

我尝试了很多方法,但仍然无法转到另一个ViewController。这是我的 Storyboard。 imgStoryboard

这是我的代码。

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
    if let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as? HistoryMainTableViewCell {
        listItems.sort() { $0.seq > $1.seq }
        let history = listItems[indexPath.row]
        cell.setValue(history: history)

        return cell
    } else {
        return HistoryMainTableViewCell()
    }
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    if segue.identifier == "vcProductHistory" {
        if let productHistoryPage = segue.destination as? HistoryProductViewController {
            if let IndexPath = tableViewHistory.indexPathForSelectedRow {
                let historyArray = listItems[IndexPath.row]
                productHistoryPage.history = historyArray
            }
        }
    }
}

最佳答案

尝试此代码:(未经测试的代码)

注意:下面的代码将触发准备转场。当选择 tableViewCell 时。让我知道代码有效...

func tableView(_ tableView: UITableView, didSelectRowAtIndexPath indexPath: IndexPath) {

   // let indexPath = myTableView!.indexPathForSelectedRow
   // let currentCell = tableView.cellForRow(at: indexPath)! as UITableViewCell
   //sendSelectedData = (currentCell.textLabel?.text)! as String as NSString
      performSegue(withIdentifier: "vcProductHistory", sender: self)
}

关于ios - TableViewCell 到 ViewController - Swift,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40326494/

相关文章:

ios - 基于 Bundle ID 的不同 App Icons 在 Build Phases->Run Script

ios - 更改导航栏的 alpha 值

ios - 带有嵌入式表格 View 的 ScrollView

ios - 通过 FTP 发送数据

swift - 任务完成的大中央调度检查

ios - 如果我使用 UITableViewAutomaticDimension,如何增加单元格的高度?

ios - 如何自动选择 UITableview Cell?

objective-c - Xcode 6.1 找不到 'debug view hierarchy' 按钮

iphone - 选择 WiFi 网络

objective-c - iOS 核心数据索引属性没有提高性能