Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS - how to move to a different page on click of a button

I am an iOS development newbie. I want to go to another page (CountryViewController) from my current page (CityViewController) on the click of a button. How would I do that? Pardon me if this is a very beginner question.

like image 383
Suchi Avatar asked Nov 02 '11 18:11

Suchi


People also ask

How do I link a button to another page in Xcode?

If you want to do this, right click drag (or control drag) from the button to the new view controller. This should make a grey line going from the first controller to the second one. You can then click on the little circle in the middle of the segue in interface builder to give it a name and specify the type.

How do I move a button in Xcode?

if you select the label and button (select them both by command + clicking them) in your storyboard then press the button that looks like a tie figher ( it looks like this: |-O-| ) at the bottom right there should be an option to clear the constraints. then you can move them around where you want them to be.

How do I put home button on iPhone?

You can: Go to Settings > Accessibility > Touch > AssistiveTouch, then turn on AssistiveTouch. Use "Hey Siri" to say, “Turn on AssistiveTouch” Go to Settings > Accessibility > Accessibility Shortcut, then turn on AssistiveTouch.

How do I make a button in SwiftUI?

SwiftUI's button is similar to UIButton , except it's more flexible in terms of what content it shows and it uses a closure for its action rather than the old target/action system. To create a button with a string title you would start with code like this: Button("Button title") { print("Button tapped!") }


2 Answers

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

    [self.navigationController pushViewController:viewController animated:YES]
like image 165
logancautrell Avatar answered Sep 30 '22 07:09

logancautrell


So basically you are trying to build a multi-view app. There are many ways to do so. Bu I'll list 3 common ones -

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

In second method, I use this controller without UINavigationTabBar. Hide this navigationBar & provide custom buttons based on which [self.navigationController popViewControllerAnimated] should occur.

like image 28
Srikar Appalaraju Avatar answered Sep 30 '22 07:09

Srikar Appalaraju