MainviewController для добавления ниже кода
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
// "SelectionSegue" is same as storyboard segue identifier
if segue.identifier == "SelectionSegue" {
(segue.destination as! SelectCategoryViewController).selectedCategoryValue = self.selectedCategoryLabel.text!
print(selectedCategoryLabel)
}
}
Установить идентификатор перехода в раскадровке
SelectedTableView
var selectedCategoryValue:String = ""
var CategeryArray = ["Food","Travel","Shopping","Card","MyReserve","Game","Songs","Movies","Entertainment","Business","Education","Finance","Drink","Sports","Social","Lifestyle"]
// Добавить методы TableView Delegate и Data Source
extension SelectCategoryViewController: UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return CategeryArray.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "TableViewCell")!
cell.textLabel?.text = self.CategeryArray[indexPath.row]
if self.CategeryArray[indexPath.row] == self.selectedCategoryValue {
cell.accessoryType = .checkmark
} else {
cell.accessoryType = .none
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
tableView.cellForRow(at: indexPath)?.accessoryType = .checkmark
self.selectedCategoryValue = CategeryArray[indexPath.row]
self.tableView.reloadData()
}
}
My View Like
NavigationController -> Mainview -> SelectedTableView