IOS - how to go to another page when a button is clicked

I am new to iOS development. I want to go to another page (CountryViewController) from my current page (CityViewController) with the click of a button. How can I do it? Forgive me if this is a very important issue.

+4
source share
4 answers

There are several ways. I assume that you are using the UINavigationController. If so, you can create a VC and do it inside your parent view controller.

[self.navigationController pushViewController:viewController animated:YES] 
+4
source

So basically you are trying to create an application with several views. There are many ways to do this. Boo, I list 3 ordinary ones -

  • [self.view insertSubview:newViewController.view atIndex:3];
  • Using UINavigationController
  • Finally, using modalViewController - [self presentModalViewController:newViewController animated:YES];

In the second method, I use this controller without a UINavigationTabBar . Hide this navigation bar and create custom buttons based on which [self.navigationController popViewControllerAnimated] .

+3
source
 ViewController2 *newView = [self.storyboard instantiateViewControllerWithIdentifier:@"viewController"]; [self.navigationController pushViewController:newView animated:YES]; 

set the storyboard identifier in ViewController2 "Identity Inspector".

0
source

I ran into the same problem. While a user registered once needs to redirect to another page, or still need to stay on the main page.

Here is a snippet of code.

Here

  N_loginmsg = @"success"; NSString *N_loginmsg = [[NSUserDefaults standardUserDefaults]objectForKey:@"remember_loginmsg"]; NSString *storyboardId; if (N_loginmsg != nil && [N_loginmsg isEqual:@"Success"]) { storyboardId = @"ListViewController"; } else { storyboardId = @"HomeViewController"; } self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main_iPhone" bundle:nil]; UIViewController *initViewController = [storyboard instantiateViewControllerWithIdentifier:storyboardId]; UINavigationController *mynav = [[UINavigationController alloc]initWithRootViewController:initViewController]; self.window.rootViewController = mynav; [self.window makeKeyAndVisible]; 
-1
source

Source: https://habr.com/ru/post/1379357/


All Articles