Reputation: 2708
In a TabBar controller I have multiple ViewControllers. I would like to access MediaDetailTableViewController
from ProfileTVC
and pass some data to it without using segues.
The schema of the StoryBoard is like this:
Tab Bar
1. Nav -> NewsFeed -> MediaDetailTableViewController
2. Nav - > ProfileTVC
From ProfileTVC I want to instantiate MediaDetailTableViewController and pass some data to it.
Using the method shown below it passes the data, but it looses the navigation bar at the top, thus I can't go back to ProfileTVC
. Also, it takes about 2 seconds to instantiate MediaDetailTableViewController.
//code inside ProfileTVC
if let selectedIndex = tableView.indexPathForSelectedRow,
selectedIndex.section != 0 && selectedIndex.section != 1 {
let mediaDetailTVC = storyboard?.instantiateViewController(withIdentifier: "MediaDetailTableViewController") as! MediaDetailTableViewController
mediaDetailTVC.currentUser = currentUser
mediaDetailTVC.media = media[selectedIndex.section]
self.present(mediaDetailTVC, animated: true, completion: nil)
}
Upvotes: 1
Views: 238
Reputation: 41
Much more simple!
performSegue(withIdentifier:"MediaDetailTableViewController", sender: self)
Upvotes: 0
Reputation: 608
PUSH instead of present
self.navigationController.push(mediaDetailTVC....)
Upvotes: 2