Pablo C. García
Pablo C. García

Reputation: 22394

Notification action open view without Navigation Controller

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)

Upvotes: 0

Views: 969

Answers (3)

Anand Nimje
Anand Nimje

Reputation: 6251

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.

Upvotes: 2

Sukhdeep Singh Kalra
Sukhdeep Singh Kalra

Reputation: 827

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.

Upvotes: 1

Chengappa C D
Chengappa C D

Reputation: 1891

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

Upvotes: 2

Related Questions