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.

4
  • 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. Commented Jun 10, 2014 at 7:43
  • @Caleb this is not duplicate.i'm using .XIb not storyboard. Commented Jun 10, 2014 at 7: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, and c) review this other duplicate. Also, SO won't be well served by a long list of questions each asking how to translate a different method. Check the docs. Commented Jun 10, 2014 at 9: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) Commented Jun 10, 2014 at 10:29

1 Answer 1

11

To simply do your exact code, use this:

    let controller = MyViewController(nibName: "MyViewController", bundle: nil)
    self.navigationController.pushViewController(controller, animated: true)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.