Notification action open view without Navigation C

2019-08-24 10:01发布

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)

3条回答
地球回转人心会变
2楼-- · 2019-08-24 10:16

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.

查看更多
唯我独甜
3楼-- · 2019-08-24 10:20

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.

查看更多
ら.Afraid
4楼-- · 2019-08-24 10:32

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

查看更多
登录 后发表回答