I am relatively new to Swift/Xcode and I am trying to make a view controller appear with different values when a button is selected (an add button) or a table view cell is selected (which allows them to edit). However, I am unable to get any response upon the selection of my row including a print statement I have put in for testing, although the segue does function when I link the transition to a button. The code is identical to that of a functioning table view cell I wrote previously that makes the current table view appear. Could this be an issue with the storyboard?
Storyboard screenshot with cell settings
Here is my code:
override func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return items.count
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "ItemCell", for: indexPath)
cell.textLabel?.text = items[indexPath.row].name
return cell
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print("Selected")
}
//Sends current receipt information to the AddItemViewController display when tapped
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "AddItemViewSegue" || segue.identifier == "EditItemViewSegue" {
let destination = segue.destination as? AddItemViewController
destination?.currentReceipt = currentReceipt
let index = tableView.indexPathForSelectedRow?.row
print("test")
if segue.identifier == "AddItemViewSegue" {
destination?.addMessage = "Add a New Item to Your Receipt"
destination?.buttonMessage = "Add Item"
}
else {
print("test1")
destination?.addMessage = "Edit an Item in Your Receipt"
destination?.buttonMessage = "Edit Item"
destination?.currentItem = items[index!]
}
}
}
I have also looked into this forum post because it is similar to mine but I was unable to apply any of the suggested fixes. https://developer.apple.com/forums/thread/14842