0

Hi I need to navigate from swift class to objective c class then I got error as

"Presenting view controllers on detached view controllers is discouraged " and displayed blank screen.

I added code to navigate as follows:

var captureViewCon = CaptureViewController(nibName: "CaptureViewController", bundle: nil)
self.presentViewController(captureViewCon, animated: true, completion: nil)

Please help me. what I did wrong?

rani
  • 593
  • 3
  • 10
  • 28
  • 1
    Where did you put this code ? What is your view controllers' hierarchy ? – ryancrunchi Nov 03 '15 at 11:50
  • You haven't provided nearly enough info. Show the method that contains this code. Explain what view controller is trying to present another, and how is the presenting view controller displayed on the screen? It sounds to me like you're calling this method on an instance of a view controller that is NOT on the screen at all. – Duncan C Nov 03 '15 at 12:24
  • I added uibutton in viewDidAppear and in button target I added code to navigate to screen – rani Nov 03 '15 at 12:52

3 Answers3

0

Try changing animated to false, or moving the code to later in your view controller's lifecycle. Or calling presentViewController from your app's rootViewController explicitly.

beyowulf
  • 15,101
  • 2
  • 34
  • 40
0

If you trying using xib file and your uiviewcontroller is in objective-c then your code is Right, but if you are trying to show uiviewcontroller which is in your stroyboard and class is in objective-c then this code having a slight change Like:-

 let captureViewCon:UIViewController = (self.storyboard?.instantiateViewControllerWithIdentifier("FirstViewController"))!
    self.presentViewController(captureViewCon, animated: true, completion: nil)

NOTE:- Make sure you import your objective c class in bridge header file.

Jagandeep Singh
  • 364
  • 4
  • 8
  • I am not using story board in swift and objective I used xib files – rani Nov 03 '15 at 13:35
  • your problem solution given in this link http://stackoverflow.com/questions/19890761/warning-presenting-view-controllers-on-detached-view-controllers-is-discourage – Jagandeep Singh Nov 04 '15 at 08:09
0

Please try to use:

let captureViewCon:UIViewController = (self.storyboard?.instantiateViewControllerWithIdentifier("FirstViewController"))! self.view.window?.rootViewController?.presentViewController(captureViewCon, animated: true, completion: nil)

Jonhory
  • 1
  • 3