0

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)
Pablo Cegarra
  • 20,955
  • 12
  • 92
  • 110

3 Answers3

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

Community
  • 1
  • 1
Chengappa C D
  • 1,841
  • 1
  • 12
  • 19
2

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.

Community
  • 1
  • 1
Anand Nimje
  • 6,163
  • 4
  • 24
  • 43
  • what is EasyExtension? – Pablo Cegarra Jun 16 '16 at 14:36
  • EasyExtension is my Custom class with Generics using for get value for Json like get any option value can get easily with this function by passing JSON and Key. – Anand Nimje Jun 16 '16 at 17:49
  • And thanxx if you need that code i can share with you. – Anand Nimje Jun 16 '16 at 17:49
  • Perfect! I was able to open my landing view using rootController but if the app was open in other view, my landing view was not opened. The other solution opened the landing page without navigation bar.... So with your solution I always open the landing view with the navigation bar. Thanks @AnandNimje – J. Fdez Jul 31 '18 at 08:55
1

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.

Community
  • 1
  • 1