Answer the question
In order to leave comments, you need to log in
How to make transition from tableview cells?
I am doing a project where I need to use a tableView by category. For example, a list of subjects Biology, Math, History, Physics, English. I click on one category (for example, Math) and I get access to Math information. My question is how to make the transition from the cell of one tableView to another controller or something else. What do I need to write in the code somehow for this? What are the ways? If something is not clear in the question, write, I will try to make it clearer.
Answer the question
In order to leave comments, you need to log in
There are several options, here is a rough example of data transfer through segue. Let's say we have an array of some data. For example, let's take a stupid array of item names . In tableViewController No. 2, create a variable to which you will pass the name of the object
. Create a seque from the cell of the first controller to the second. You assign id "Seque" to this seque. Next, in tableViewController No. 1, write the method:let array = ["математика", "физика"]
var name = ""
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "Seque" {
if let indexPath = self.tableView.indexPathForSelectedRow {
let destinationVC = segue.destination as! SecondTableViewController
destinationVC.name = self.array[(indexPath as NSIndexPath).row]
}
}
}
The usual segue from the cell to the VC you need.
Google it, it's full of articles.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question