MrPool
MrPool

Reputation: 401

pushViewController is unable to perform segue

I want to perform a segue to a detailed view, when the user clicks on the row. The code which is present has worked to perform this same task in previous projects as well, so I'm not sure where I could be going wrong here.

Here is the snippet for the didSelectRowAt function:

func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        print(indexPath.row)
        tableView.deselectRow(at: indexPath, animated: true)

        let postsInfo = posts[indexPath.row]
        print(postsInfo)
        let Storyboard = UIStoryboard(name: "Main", bundle: nil)
        let DvC = Storyboard.instantiateViewController(withIdentifier: "NewsFeedDetailedController") as! NewsFeedDetailedController
        DvC.getTitle = postsInfo.title.title
        print(postsInfo.title.title)
        DvC.getSubtitle = postsInfo.description
        print(postsInfo.description)
        DvC.getImg = postsInfo.title.photoURL.absoluteString
        print(postsInfo.title.photoURL.absoluteString)
        DvC.getDate = postsInfo.postdate
        print(postsInfo.postdate)

        self.navigationController?.pushViewController(DvC, animated: true)
    }

All the data is being printed in the console, so I'm certain that there is no problem from my database, which is a Firebase Realtime Database.

I've also given the Storyboard ID of NewsFeedDetailedController for the Detailed View Controller.

Upvotes: 1

Views: 76

Answers (1)

MavericksCuba
MavericksCuba

Reputation: 186

The problem must be that the navigationController = nil. That means that in your hierarchy you don't have a navigationController. In that case you must do

present(DvC, animated: true, completion: nil)

Good luck

Upvotes: 2

Related Questions