gpt4 book ai didi

swift - 如何使用 tabbarcontroller 通过弹出窗口的展开转场导航到 View

转载 作者:行者123 更新时间:2023-11-30 12:43:16 25 4
gpt4 key购买 nike

我的所有 View Controller 都使用选项卡栏 Controller 链接,并且效果很好。我唯一的问题是,当显示弹出窗口时,我无法在适当的情况下将用户发送到另一个 View Controller 。我尝试使用

tabBarController.selectedIndex = 1

这是一些相关代码:

//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)
}
}

这是触发拾取弹出窗口的地方。这是展开转场:

 @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)
}
}
}

这是我发送到扫描仪 View Controller 的函数:

func sendToMoveView()
{
guard let tabBarController = tabBarController else { return }
tabBarController.selectedIndex = 1
}

我尝试在像我的 viewDidAppear 覆盖这样的地方使用 tabBarController.selectedIndex ,它适用于设置默认 View 或布局 subview ,并且在 AppDelegate 中使用它之前我已经设置了默认 View 。那么在这种情况下我必须做什么才能使用它,因为以任何其他方式导航到 VC 都会给我一个没有选项卡栏的 VC :( 我非常感谢任何帮助,谢谢。

最佳答案

我在这个问题中找到了答案的线索:Change UITabbar selectedItem in Swift

然后,我从初始 View Controller 中删除了展开转场,并将其嵌入到选项卡栏 Controller 中,并将我的 sendToMoveView 函数更改为如下所示:

func sendToMoveView()
{
self.selectedViewController = self.viewControllers?[1]
}

为了安全起见,我还在 Storyboard中重新设置了展开连接,即使它显示了正确的 Controller 。只是想指出,如果您没有为选项卡栏 Controller 提供正确的 Storyboard ID,我所做的更改将不起作用。这个让我很头疼。

关于swift - 如何使用 tabbarcontroller 通过弹出窗口的展开转场导航到 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41991199/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com