How to open another view when button is clicked in iOS app development? - swift4

I am trying to build an app, and I want another view to open up once I click a button. I have searched for an answer, but nothing came up. I already have the button done, but I don't know how to get another view to show up. The view should be another view within the app. I am just a beginner in xCode. Thanks.
I am currently using xCode 9, and swift 4. Thanks.

You can approach this either using the storyboard or programmatically. Using the storyboard, you can ctrl-drag from the button to the other view controller and the segue will be wired up for you, like so:
If you aren't using storyboards at all, you can use the .show method of the ViewController in the button action. Apple has a good guide on segues.

Related

Button in swift to connect to a random storyboard (Xcode version 8.2.1

I am new to swift / Xcode and I am trying to create a button in Xcode that can randomly transfer to a different storyboard. I tried following the instructions in this post to do it (I also tried other ideas, but this answer was the most intuitive)
How to Segue Randomly to ViewControllers in Swift?
I've written the IBAction and connected the extra storyboards with different segues to the root view controller but when I start the simulation nothing happens when I click the "go" button. I cannot connect this button with the IBAction by a control drag, so I think that may be the problem.
I've tried creating new projects, connecting the "go" button to the root view controller, and editing the classes (it doesn't let me). What else could be wrong? My code is exactly like the answer to the link I posted. Is there a step missing to that answer?
First make sure you created a custom class for your root view controller. Also make sure you assigned your custom class to the view controller in Interface Builder.
Try dragging from your button to the view controller code pane and let XCode create the IBAction stub for you. Now touching the button should trigger your IBAction.

Go back to previous storyboard

I'm currently developing a framework in Swift that includes a storyboard that I designed myself. What I need to do is that the user that uses my framework can create a segue to my storyboard. Then I'd like to be able to recreate a segue to the user storyboard that that I "leave" my storyboard.
How could I do so ?
Thx !
Your question is vague and I am not entirely sure what you are asking. However, I can't comment yet so I will try to answer with what little I know. It seems like you are asking how to transition storyboards. The simplest way is using a UIButton in your storyboard. Open up storyboard and go to the navigation controller. Then, add a button to the Nav Controller. Right click (or control click, depending on your settings), and drag the line to the main storyboard. Lastly, click on the show option. When a user clicks on the button, it will immediately switch to the main view controller. Don't forget to add the button in the view controller. Hopefully, this is what you meant and helps. If you wish switch view controllers in code, this is a duplicate and you should go here: How to switch view controllers in swift?. If this doesn't answer your question, comment and I will try and help. For future reference, please provide more information: snippets of code, pictures, anything that better demonstrates your problem.
I fixed it by getting the instance of a new view controller added on the user storyboard with the view controller identifier like so :
ProcessOut.backViewController = storyboard?.instantiateViewControllerWithIdentifier("back")
And then I present it like I would present a normal viewController from my storyboard.

XCODE 5 - Storyboard Segues Push vs Modal

I am currently learning iOS development and I began with a simple Tabbed Application. It has the default First and Second View in it. I added a TableView with static cells content. I then added another View Controller. I created a Segue using the storyboard. When I set the transition to modal, it works fine. When I set it to push, the app is crashing (Uncaught exception).
Any idea why?
How can I get more information regarding the exception? Can I make the app stops when it encounters an exception?
Figured it out.. I need to add a Navigation Controller to use push...

Switching between views not working for iPhone 5.1 (XCode 4.3.2)

I'm trying to develop an iPhone app that uses 4 views(View-based app), and I want to navigate from one view to the other. It would be ideal if for example the Submit ID button automatically sent a message to UIViewController to switch to View 2, and selecting a cell in View 2 would load View 3.
See a screenshot of the Storyboard here.
I'm not sure how to do that, so I've tried using a separate button to switch between views, but that isn't working either and I can't figure out why.
You can have a look at the source code which I've uploaded to Dropbox.
First, I would suggest posting your code in your question. As appreciative as I'm sure other people are that you provided a dropbox link to the code, most people presumably have little interest in downloading the file to their computer, unzipping, and launching the project (me being one of them).
That being said, let's make sure you're clear on Storyboards and the general view controller hierarchy principles. You have, in your storyboard, four UIViewControllers dragged out into your workspace. So, you're not switching the views of a single UIViewController, telling it to switch from View1 to View2 to View3 and so on. You need to be telling the view controller hierarchy (which, in your case, probably needs to be managed by a UINavigationController), to push and/or pop view controller on and off its stack. It appears that you have some segues set up between your view controllers. Are you calling performSegueWithIdentifier:sender: in your code? Alternatively, you could hook up the Submit ID button to perform a push segue to View Controller 2 in much the same manner.
Once you have that working, you can override prepareForSegue:sender: to send information from ViewController1 to ViewController2 and so on.

iOS5 - Storyboard - showing another view

This is simple one though:
I'm having XCode 4.2 with iOS beta7. I am just trying a to have to views with one button in first view. On click of button, it will show next view.
In many tutorials, when I click and drag the button to next view, it will show "performSegueWithIdentifier:sender:" view.
But in my interface builder, its showing "Storyboard Segues with Push, Modal, Popover, Custom......"
I don't know whether I'm doing wrong or its the behavior of the xcode itself....
can some one suggest me good tutorials for iOS5 storyboard please?
Yes, you doing everything right. Push, Modal are types of showing next screen (UIView). You need to select it according Human Interface Guidelines from Apple.