为什么我的tableView在内部无法推送到detailViewController?

huangapple go评论64阅读模式
英文:

why is my tableView not pushing to the detailViewController inside my tableView?

问题

I'm creating a Twitter clone, and for some reason, when a user taps on a cell, it should go to the detailViewController to show them more about the tweet, but it never pushes. And I know the problem is not something like chest to make sure you have the correct storyboard ID because when I make the tableView the initial view controller it pushes to the detail view controller. So IDK if this a bug in the code or in the view hierarchy, etc.

I tried just doing a segue but it was the same problem and made sure that it's the right class in storyboard.

Here's my GitHub to see if anyone can find the bug or problem with the tableView cell not pushing to the detailViewController:

GitHub Link

Here are some code snippets as well of where the bug may be:

Image 1

Image 2

英文:

Im creating a twitter clone and for some reason when a user taps on a cell it should go to the detailViewController to show them more about the tweet but it never pushes. And I know the problem is not something like chest to make sure you have the correct storyboard ID because when I make the tableView the initial view controller it pushes to the detail view controller. So IDK if this a bug in the code or in the view hierarchy etc.

I tried just doing a segue but it was the same problem and made sure that its the right class in storyBoard.

here's my GitHub to see if anyone can find the bug or problem with the tableView cell not pushing to the detailViewController,

<https://github.com/imjusttrynabelikeElon/twitter/tree/main>

here's some code snippets as well of where the bug may be.

enter image description here

enter image description here

答案1

得分: 2

我已经克隆了你的项目并进行了检查。
这部分代码是有效的:

let storyBoard = UIStoryboard.init(name: "Main", bundle: nil)

guard let vc = storyBoard.instantiateViewController(withIdentifier: "detail") as? TwitterHomeViewDetailViewController else {
    print("failed to instantiate detail view controller")
    return
}
英文:

I have cloned your project and checked.
This is working :

        let storyBoard = UIStoryboard.init(name: &quot;Main&quot;, bundle: nil)
    
        guard let vc = storyBoard.instantiateViewController(withIdentifier: &quot;detail&quot;) as? TwitterHomeViewDetailViewController else {
        print(&quot;failed to instantiate detail view controller&quot;)
        return
        }

答案2

得分: 2

这应该有效。

if let vc = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "detail") as? TwitterHomeViewDetailViewController {
// 进行你想做的操作。
} else {
assertionFailure("失败!")
}

英文:

This should work.

if let vc = UIStoryboard(name: &quot;Main&quot;, bundle: nil).instantiateViewController(withIdentifier: &quot;detail&quot;) as? TwitterHomeViewDetailViewController {
    // Do what you want.
} else {
    assertionFailure(&quot;Failed!&quot;)
}

huangapple
  • 本文由 发表于 2023年5月10日 15:45:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/76216046.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定