简体   繁体   English

如何修复显示灰色屏幕的 segue

[英]How to fix segue showing a grey screen

I wanted to create a segue going from FirstViewController to DetailViewController, but when I write我想创建一个从 FirstViewController 到 DetailViewController 的 segue,但是当我写

        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() .问题是短语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 https://developer.apple.com/documentation/uikit/uistoryboard/1616214-instantiateviewcontroller

Now cast that view controller down to DetailViewController and go from there.现在将该视图控制器投射到 DetailViewController 并从那里开始。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM