IOS - How to program navigation between Viewcontroller in Objective-C?

Asked

Viewed 318 times

0

I want to navigate between the Viewcontroller of an app by clicking on a button and switching from one to the other for example. But I didn’t want to do it by . storyboard, I want to do it directly via code. Is it possible? If yes, how can I do it.

  • 1

    You also want to create UIViewController by code or they will come from your storyboard?

  • It’ll come from the storyboard

1 answer

1


You can use the methods pushViewController: or presentViewController:. First you need to get an instance of your UIViewController which will be opened and which is in the storyboard through the identifier:

SegundaViewController *viewController = [self.storyboard instantiateViewControllerWithIdentifier:@"segundaView"];

Now you do the push from the navigationController:

[[self navigationController] pushViewController:viewController animated:YES];

Or open like a modal:

[self presentViewController:viewController animated:YES completion:nil];
  • It worked perfectly, thanks, but if I use inside the viewDidLoad it doesn’t work. You know how I can fix this?

  • 1

    You intend that as soon as you open a screen, run this code to open another?

  • Yes, in case, the home screen is a registration, however, I check it if the customer has already been registered, if yes, I wanted to send it straight to the home screen of the app.

  • 1

    If possible, even the snippet of your code that is on viewDidLoad. But since this is another question, I suggest creating a new question just for this question.

  • http://answall.com/questions/115759/ios-comoprogramr-navigator%C3%A7%C3%A3o-entre-viewcontroller-direto-na-viewdidload

Browser other questions tagged

You are not signed in. Login or sign up in order to post.