Jevon Cowell
Jevon Cowell

Reputation: 411

Storyboard Button Segue

So I'm new to Xcode, and I'm making an app where basically every single screen has this button, for this case I'll say a search button. This search button is available on nearly every screen so a user can search no matter what screen they are on. The only problem with this is design wise, this causes a massive gloat of segue arrows to flow into it, as well as allot of arrows flowing from it due to 4 other buttons also being available everywhere.

Is there a way to sort of to make this button on all View Controllers automatically go to just one View Controller responsible for Searching in a way that doesn't make design messy?

Here's a view: Storyboard

Upvotes: 2

Views: 647

Answers (3)

Bassam
Bassam

Reputation: 856

You means , need make the same search button on all screen ?

You can make that by add this button to top of view and added container view

and show all view you want in this view .

Upvotes: 0

Duncan C
Duncan C

Reputation: 131491

You have a couple of options. As Elaina suggests in her answer, you can control-drag from your button to another scene in your storyboard to create a segue directly from the button.

However, to do that you'll likely need a prepareForSegue method, which is custom code.

What I suggest you do is to create a custom subclass of UIViewController and put an IBAction method and a prepareForSegue method in it.

Make the IBAction method invoke another view controller and push/present it modally, whatever you want. (That way you won't have to connect lots of segues to the same destination view controller.)

All you have to do is to control-drag from the button on each of these view controllers to the IBAction in the base class. Simple.

Upvotes: 1

Elaina
Elaina

Reputation: 214

If you are looking to clean up your storyboard, you could do the push programatically. Inside the click event for your search button, you could use this code to programmatically present the view for your search view controller:

presentViewController(searchViewController, animated: true, completion: nil)

Upvotes: 0

Related Questions