1

I have 3 view controllers - a button on the navigation bar modally presents a tableview from which when you select a row I want to dismiss it and present a new view controller

However when I click the row the table dismisses but doesn't present the new view controller

this is the code from the button to instantiate the second tableview view controller.

@IBAction func gotofriends(_ sender: Any) {
    let storyboard = UIStoryboard(name: "Groups", bundle: nil)
    let newVC = storyboard.instantiateViewController(withIdentifier: "FriendsList") as! FriendsListToMessage
    DispatchQueue.main.async {
    self.navigationController?.present(newVC, animated: true, completion: nil)
    }
}

this is my storyboard .enter image description here

this is the code for the second view controller to show the third - in the completion block from the dismiss is the code to instatiate a new view controller.

 func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let cell = tableView.cellForRow(at: indexPath)!
        let username = cell.textLabel!.text ?? ""
        DispatchQueue.main.async {
            self.dismiss(animated: true) {
            let storyboard = UIStoryboard(name: "Groups", bundle: nil)
            let newVC = storyboard.instantiateViewController(withIdentifier: "MessageView") as! MessageLog
            DispatchQueue.main.async {
            self.navigationController?.present(newVC, animated: true, completion: nil)
            }

        
            }
        }
    }

0 Answers0