我有一个客户选项卡控制器,该控制器带有一个自定义图标,当用户单击弹出菜单时,该图标带有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
}
}
}
Run Code Online (Sandbox Code Playgroud)
这是显示流程的图像。用户单击相机按钮,然后出现一个弹出菜单,当用户单击某个选项时,我要将其带到新的视图控制器(未连接至选项卡栏控制器)。我设置了第一个链接以转到新的视图控制器,它显示了几秒钟,然后消失了。
您为segue方法使用了不同的标识符,
performSegue(withIdentifier: "showScanBarcode", sender: nil)
和
prepare(for segue: UIStoryboardSegue, sender: Any?)。
因此,请使用相同的标识符。希望这会帮助你。
那是 PopMenu 的问题。
PopMenuManager 在最顶层视图控制器上显示 UIViewController 并在选择后调用 Dismiss() 。取消会递归遍历所有控制器。当他这样做时,您的新视图控制器是否位于最顶层并收到解雇。在单独的线程中进行转场可能会有所帮助。(可能还有短暂的测试延迟)
let action1 = PopMenuDefaultAction(title: "Scan Barcode", didSelect: { action in
DispatchQueue.main.async {
self.performSegue(withIdentifier: "showScanBarcode", sender: nil)
}
print("\(String(describing: action.title)) is tapped")
})
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
274 次 |
| 最近记录: |