【问题标题】:Swift UITableViewCell Segue To another ViewSwift UITableViewCell Segue 到另一个视图
【发布时间】:2017-07-23 07:04:47
【问题描述】:

我正在尝试制作一个音乐播放器,在一个视图中,我有一个 UITableView 的播放列表,我希望当用户点击一个单元格时,它会转到另一个包含歌曲列表的 UITableView在播放列表中。执行此操作时,我收到以下错误:

"2017-07-22 23:58:35.479139-0700 FoodTracker[740:118055] ; layer = ; contentOffset: {0, 0}; contentSize: {375, 1080}> 的 窗口不等于 's 视图的窗口!”

项目的名称是 foodTracker,因为我在 Apple 教程项目的基础上构建了一个测试项目。此外, playlistTable 是带有歌曲的表格视图。不是播放列表。有什么办法可以解决这个错误吗?

我的tableView()代码如下:

override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
    NSLog("You selected cell number: \(indexPath.row)!")

    tableView.deselectRow(at: indexPath, animated: true)

    let thePlaylist = playlistArray[indexPath.row].songs
    songsToShow = loadSongs(songs: thePlaylist)
    let storyboard = UIStoryboard(name: "Main", bundle: Bundle.main)
    let destination = storyboard.instantiateViewController(withIdentifier: "playlistTable") as! playlistTable
    destination.songArr =  songsToShow
    navigationController?.pushViewController(destination, animated: true)

    performSegue(withIdentifier: "goTo", sender: self) 

}

【问题讨论】:

  • 这 2 个UITableViews 是在相同的视图中还是不同的视图中?

标签: ios iphone swift uitableview uistoryboardsegue


【解决方案1】:

你为什么同时做这两个?删除其中之一。

navigationController?.pushViewController(destination, animated: true)

performSegue(withIdentifier: "goTo", sender: self)

【讨论】:

    【解决方案2】:

    @JuatANoob 我认为您在代码 sn-p 中犯了一些基本错误,因此无需在同一个 sn-p 中同时执行 pushNavigation 和 performSegue 的代码。一个 sn-p 中的两件事都会让人感到困惑。所以你只需要对你的代码做一件事。 pushNavigation 或 performSegue。

    【讨论】:

      【解决方案3】:

      如果您不需要通过故事板继续,只需评论此行。

      performSegue(withIdentifier: "goTo", sender: self) 
      

      【讨论】:

        猜你喜欢
        • 2012-02-20
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-11-30
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多