1

How can i switch one UIViewcontroller to another UIViewController in Swift language? I 'm create a new empty project and and set UINavigationcontroller and not using story board.

For example we use this code in objective c for pushing view controller

MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyViewController"    bundle:nil];
[self.navigationController pushViewController:controller animated:YES]

What is the alternative in Swift ?

Any help can be appreciated Thanks in advance.

Akhtar
  • 3,172
  • 5
  • 19
  • 21
  • 1
    If you're using Xcode 6 then have a go at writing what you think it is. It really isn't hard enough to be put on a Stack Overflow question. The code completion will show you what it is if you actually have a go. – Fogmeister Jun 10 '14 at 07:43
  • @Caleb this is not duplicate.i'm using .XIb not storyboard. – Akhtar Jun 10 '14 at 07:57
  • 1
    @Austin_ak The title and content of your question seem to focus on pushing a controller rather than instantiating one. If you're really asking about instantiation, please a) edit your question, b) check [the docs](https://developer.apple.com/library/prerelease/iOS/documentation/UIKit/Reference/UIViewController_Class/index.html#//apple_ref/occ/instm/UIViewController/initWithNibName:bundle:), and c) review [this other duplicate](http://stackoverflow.com/q/24046898). Also, SO won't be well served by a long list of questions each asking how to translate a different method. Check the docs. – Caleb Jun 10 '14 at 09:02
  • Thank you very much for you suggestion @Celeb. I want to create the instance of view controller and i solve my issue using this line of code var viewC: testViewController? = testViewController(nibName: "testViewController", bundle: nil) – Akhtar Jun 10 '14 at 10:29

1 Answers1

11

To simply do your exact code, use this:

    let controller = MyViewController(nibName: "MyViewController", bundle: nil)
    self.navigationController.pushViewController(controller, animated: true)
Matthew Knippen
  • 1,048
  • 9
  • 22