Transfer the body from one ViewController'a to another
-
I'm writing an iTunes application (2 deposits: Search and History).
Possk is being issued
TableView
With a list of albums. When pressed on the album,ShowInfoViewController
(sighs)ViewController
with album information.I want this moment when you press the album, other than the appearance.
ShowInfoViewController
and sent data toHistoryViewController
♪How can I just put the data in another controller without opening it up?
View
, how does this happen when calling the methodpresent
? (LAUGHS)HistoryViewController
)func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let album = albums[indexPath.row] let infoController = self.storyboard!.instantiateViewController(withIdentifier: "showInfo") as! ShowInfoViewController infoController.album = album self.present(infoController, animated: true, completion: nil) let historyController = self.storyboard!.instantiateViewController(withIdentifier: "history") as! HistoryViewController historyController.albums.append(album)
}
P.S. If you just take it away.
present
There's nothing in the other two. Thank you.
-
It would be logical to receive and update the data in itself.
HistoryViewController
when switching to it. To this end, history data can be placed in a temporary (replaceable with general access/syngleton) or permanent storage facility (database). But if you're so eager to update the data directly in another vue counteraller, and you're sure it exists at the time of notification, it's better to use the notification or delegation mechanism, there's a lot of information about it.struct History { var albums: [Album] }
Then when switched to
HistoryViewController
data can be collected for exampleviewWillAppear