Notification action open view without Navigation C

2019-08-24 09:32发布

问题:

I'm doing an app which opens a detail view from a push notification. In my AppDelegate I'm opening the view, but the view doesn't have a navigation controller.

Then I think that my solution is use the method instantiateViewControllerWithIdentifier to handle the navigation controller, I'm not sure if this is the solution, but here is the question of the title...

My class SlideNavigationController is Objective-C, and when I use the method

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

I get the error:

warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.

Any idea? Sorry for my English, edits are welcome! Thanks

The problem with my UIController is solved. Here is my code:

           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)

回答1:

You can do with this code.

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)

I hope this will help you.



回答2:

You can programatically create a navigation Controller and set the desired view controller as its rootViewController of the navigation controller and then set navigation controller as windows rootViewController.

eg :

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

Same is expalined in this link too : set initial viewcontroller in appdelegate - swift



回答3:

You must need to create a bridging header to use objective c controllers in the swift project.

Follow the link below for information on creating bridging header.

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

After that you must import the .h files of controllers in the bridging header file.

Now you can easily use your objective c view controller in swift project.