如何区分各种NavigationController?

问题描述 投票:0回答:1

我在我的应用程序中使用多个NavigationController

let navViewController = UINavigationController(rootViewController: vc)

将标签指定为

navViewController.navigationBar.tag = 10

&取为

if navigationController?.navigationBar.tag == 10 {

相反navigationBar.tag,我们不能使用navViewController引用或navigationController.tag区分?

ios swift uinavigationcontroller
1个回答
2
投票

使用标签区分导航控制器是可以的。为了使代码更具可读性并避免任何可能的错误,您可以将标记定义为常量或枚举,并检查常量值。

另一种方法是为每个案例子类化UINavigationController并检查相应的类:

if let navController = navigationController as? CustomNavigationController {
  //your code
}

子类化增加了样板并使项目更大。因此,如果您不需要在每个导航控制器上进行任何自定义,则可以继续使用标记。

© www.soinside.com 2019 - 2024. All rights reserved.