【发布时间】:2019-05-02 02:22:27
【问题描述】:
我有一个客户选项卡控制器,它有一个自定义图标,当用户单击弹出菜单时会出现 3 个选项。当我单击第一个选项时,它应该将我带到一个新的视图控制器,但是当我单击它时,视图控制器只会出现一秒钟,然后再次消失。我不知道为什么,但这是我的客户标签栏代码:
import UIKit
import PopMenu
class TabBarController: UITabBarController, UITabBarControllerDelegate {
override func viewDidLoad() {
delegate = self
}
func tabBarController(_ tabBarController: UITabBarController, shouldSelect viewController: UIViewController) -> Bool {
if viewController.title == "for custom action" {
let manager = PopMenuManager.default
let action1 = PopMenuDefaultAction(title: "Scan Barcode", didSelect: { action in
self.performSegue(withIdentifier: "showScanBarcode", sender: nil)
print("\(String(describing: action.title)) is tapped")
})
let action2 = PopMenuDefaultAction(title: "Action 2", didSelect: { action in
print("\(String(describing: action.title)) is tapped")
})
let action3 = PopMenuDefaultAction(title: "Action 3", image: UIImage(named: "wine"), didSelect: { action in
print("\(String(describing: action.title)) is tapped")
})
manager.addAction(action1)
manager.addAction(action2)
manager.addAction(action3)
manager.present()
return false
}
return true
}
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "mySegue" {
let controller = segue.destination as! myViewController
controller.navigationItem.leftBarButtonItem = splitViewController?.displayModeButtonItem
controller.navigationItem.leftItemsSupplementBackButton = true
}
}
}
这是显示流程的图像。用户单击相机按钮,然后出现一个弹出菜单,当用户单击一个选项时,我想将它们带到一个新的视图控制器(未连接到标签栏控制器)。我设置了第一个链接到一个新的视图控制器,它显示了几秒钟然后消失了。
【问题讨论】:
-
showScanBarcode做了什么样的转场(推送、弹出、呈现)?添加更多代码细节,例如故事板和showScanBarcodes viewcontroller 类 -
这是一个 push segue,在 IB 中创建,标识符为 showScanBarcode ... scowScanBarcode 类现在是空的,它只是一个模板
-
TabBarController 是否嵌入在
UINavigationController中以使 push segue 工作? “视图控制器只出现一秒钟,然后再次消失”请详细说明 -
我在描述中添加了更多信息,TabBarController 没有嵌入到导航控制器中,但是 TBC 中的一些屏幕是嵌入的。当他们单击中间图标时,会出现一个自定义弹出窗口,我希望用户单击其中一个选项并被引导到与标签栏控制器无关的单独视图控制器,如果这有意义的话
-
@user2647092 我认为您需要将 (segue.identifier == "mySegue") 更新为 (segue.identifier == "showScanBarcode")