英文:
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:
Here are some code snippets as well of where the bug may be:
英文:
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.
答案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: "Main", bundle: nil)
guard let vc = storyBoard.instantiateViewController(withIdentifier: "detail") as? TwitterHomeViewDetailViewController else {
print("failed to instantiate detail view controller")
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: "Main", bundle: nil).instantiateViewController(withIdentifier: "detail") as? TwitterHomeViewDetailViewController {
// Do what you want.
} else {
assertionFailure("Failed!")
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论