I'm new to coding, but I've been working on the same issue for days. I'm trying to push the menuItem
to join an array in a new view controller scene called OrderController
when the cell row is selected. menuItem
is a class, and it gets added to an array of MenuItems
in OrderList
on the next page.
The closest I was to making this happen was putting orderList.add
within the didSelectRowAt
function, but it would just take the orderList
from the current TableView
, but this method doesn't work well because it won't update the values on the next page.
This is the code below:
var orderList = OrderList()
let menuItems = PaneraMenu()
var menuItem = MenuItems()
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let row = indexPath.row
let order = menuItems.items[row]
navigationItem.title! = order.name
orderList.add(menuItem: order)
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "paneSell"{
let yo = segue.destination as! OrderController
yo.orderList = orderList
}
}