All of my view controllers are linked using a tab bar controller, and it works great. My only issue is when a popover is displayed I am unable to send the user to another view controller for the appropriate circumstance. I tried using
tabBarController.selectedIndex = 1
Here is some pertinent code:
//user selects a row this function triggers an event
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView == self.tableviewlineneeds
{
forklift.paramneeds = "\(forklift.k)&f=\(forklift.forkliftid)&id=\(forklift.needuniqueid[(indexPath as NSIndexPath).row])&o="
let popneeds = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "verifyneedsaction") as! NeedsActionPopover
popneeds.modalPresentationStyle = UIModalPresentationStyle.popover
popneeds.popoverPresentationController!.delegate = self
popneeds.popoverPresentationController?.permittedArrowDirections = .any
popneeds.popoverPresentationController?.sourceView = tableviewlineneeds
popneeds.popoverPresentationController?.sourceRect = tableviewlineneeds.rectForRow(at: indexPath)
popneeds.preferredContentSize = CGSize(width: 225, height: 180)
popneeds.needitem = forklift.itemneeds[(indexPath as NSIndexPath).row]
self.present(popneeds, animated: true, completion: nil)
}
if tableView == self.tableviewlinepickup
{
forklift.parampickup = "\(forklift.k)&f=\(forklift.forkliftid)&id=\(forklift.pickupuniqueid[(indexPath as NSIndexPath).row])&o="
let poppickup = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "verifypickupaction") as! PickupActionPopover
poppickup.modalPresentationStyle = UIModalPresentationStyle.popover
poppickup.popoverPresentationController!.delegate = self
poppickup.popoverPresentationController?.permittedArrowDirections = .any
poppickup.popoverPresentationController?.sourceView = tableviewlinepickup
poppickup.popoverPresentationController?.sourceRect = tableviewlinepickup.rectForRow(at: indexPath)
poppickup.preferredContentSize = CGSize(width: 300, height: 180)
forklift.pickuplocation = forklift.locationpickup[(indexPath as NSIndexPath).row]
poppickup.pickupitem = forklift.itempickup[(indexPath as NSIndexPath).row]
self.present(poppickup, animated: true, completion: nil)
}
}
That is where the popup for the pickup is triggered. and here is the unwind segue:
@IBAction func unwindLinePickup(_ segue: UIStoryboardSegue)
{
if segue.identifier == "confirm"
{
switch forklift.pickuplocation
{
case "Line 2":
self.sendToMoveView()
case "Line 3":
self.sendToMoveView()
case "Line 7":
self.sendToMoveView()
case "Line 8":
self.sendToMoveView()
default:
API.HTTPCall(forklift.parampickup, url: forklift.postmove!, method: "POST", int: 10)
}
}
}
and this is my function to send to the scanner view controller:
func sendToMoveView()
{
guard let tabBarController = tabBarController else { return }
tabBarController.selectedIndex = 1
}
I have tried using the tabBarController.selectedIndex in places like my viewDidAppear override and it works for setting a default or the layout subviews, and I have set a default view before using it in the AppDelegate. So what must I do to use it in this situation, because navigating to the VC any other way gives me a VC with no tab bar :( I'd greatly appreciate any help, Thanks.