代码之家  ›  专栏  ›  技术社区  ›  Pablo Cegarra

没有导航控制器的通知操作打开视图

  •  0
  • Pablo Cegarra  · 技术社区  · 8 年前

    我正在做一个应用程序,它可以从推送通知中打开详细视图。 在我的AppDelegate中,我正在打开视图,但视图没有导航控制器。

    那么我认为我的解决方案是使用 instantiateViewControllerWithIdentifier 要处理导航控制器,我不确定这是否是解决方案,但这里是标题的问题。。。

    我的班级 SlideNavigationController 是Objective-C,当我使用该方法时

    let rootVC = UIStoryboard(name: "Main", bundle: nil).
    instantiateViewControllerWithIdentifier("SlideNavigationController") as! SlideNavigationController
    

    我得到错误:

    警告:无法加载任何Objective-C类信息。这将大大降低可用类型信息的质量。

    知道吗?对不起,我的英语,欢迎编辑!谢谢

    我的UIController的问题解决了。这是我的代码:

               let rootViewController = self.window!.rootViewController as! UINavigationController
                let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
                let targerView = mainStoryboard.instantiateViewControllerWithIdentifier("view_place_detail") as! VCPlaceDetailTour
                targerView.placeId = aps as String
                rootViewController.pushViewController(targerView, animated: false)
    
    3 回复  |  直到 8 年前
        1
  •  2
  •   Community CDub    4 年前

    您可以使用此代码。

    let rootViewController = self.window!.rootViewController as! UINavigationController
    let mainStoryboard: UIStoryboard = UIStoryboard(name: "Main", bundle: nil)
    let targerView = mainStoryboard.instantiateViewControllerWithIdentifier("view Identifier") as! PromotionDetailsVC
    rootViewController.pushViewController(targerView, animated: false)
    

    我希望这对你有帮助。

        2
  •  2
  •   Community CDub    7 年前

    您可以通过编程方式创建导航控制器,并将所需的视图控制器设置为导航控制器的rootViewController,然后将导航控制器设置为windows rootViewController。

    如:

    let rootVC = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("SlideNavigationController") as! SlideNavigationController
    let window = UIApplication.sharedApplication().keyWindow
    window.rootViewController = rootVC
    

    此链接中也有相同的解释: set initial viewcontroller in appdelegate - swift

        3
  •  1
  •   Community CDub    7 年前

    您必须创建桥接头才能在swift项目中使用目标c控制器。

    有关创建桥接头的信息,请访问下面的链接。

    How to find path of Bridging-Header.h - Swift, Xcode

    之后,必须在桥接头文件中导入控制器的.h文件。

    现在,您可以在swift项目中轻松使用目标c视图控制器。