简体   繁体   中英

How to connect a button to a new view controller iOS Swift?

I'm pretty new to Swift and am trying to connect a button to another View Controller. On other apps I have made with Swift I have been able to easily control-drag a button to another view controller, where it would display "show" as an option to click. When I would run it and click the button it would show the desired View Controller.

On the app I am working on, I was trying to add a settings page that could be accessed by clicking a button. When I tried to control-click and drag the button into the second view control, it displayed only three options: push, modal, and custom. I selected push, and when I ran the app and pressed the button it showed a SINABRT error. How can I connect a button to a second View Controller just by pressing it?

You will only see the "show" option if you are working on a project targeting iOS 8 and later, since it is a new feature to help you to determine the proper way to show your new view controller. It will opt to "push" if you are in a navigation controller and "modal" if you are in a regular controller context.

Here you might be working for a project with deploy target for iOS 7 or below. You can choose to use "modal" here to present the view controller from the bottom of screen and implement an exit button. Or you can embed your current view controller into a navigation controller to use "push" to make the new view controller pushed from right hand to left, with a back button to navigating back automatically.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM