I wanted to create a segue going from FirstViewController to DetailViewController, but when I write
let detailVC = DetailViewController()
detailVC.result = indexPath.row
print(detailVC.result)
self.present(detailVC, animated: true, completion: nil)
, all it presents is a grey/transparent screen. How can I fix this?
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return posts.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "PostCell", for: indexPath) as! PostTableViewCell
cell.typeLabel.text = "Name: \(posts[indexPath.row].typeOfFood)"
cell.titleLabel.text = "Title: \(posts[indexPath.row].title)"
cell.locationLabel.text = "Location: \(posts[indexPath.row].location)"
cell.nameLabel.text = "Name: \(posts[indexPath.row].name)"
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
// print("Select Row \(indexPath.row)")
var result = indexPath.row
tableView.deselectRow(at: indexPath, animated: true)
// self.performSegue(withIdentifier: "showDetail", sender: nil)
let detailVC = DetailViewController()
detailVC.result = indexPath.row
print(detailVC.result)
self.present(detailVC, animated: true, completion: nil)
}
} ```
The problem is the phrase
DetailViewController(). That's not you get the detail view controller you designed in the storyboard.Instead, give the view controller you designed in the storyboard an identifier, and ask the storyboard for that view controller by calling this method:
https://developer.apple.com/documentation/uikit/uistoryboard/1616214-instantiateviewcontroller
Now cast that view controller down to DetailViewController and go from there.