Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get a custom UIControl to participate in a segue as a push action?

I have a custom class that inherits from UIControl, to get touch events. It's basically a collection of other controls that acts as one. I'm converting my app from xibs to a storyboard. It's been mostly painless, except for this.

I drag a UIView into my scene, change the class to my custom control, hook it up to outlets on my ViewController. What I want to do with the control when it's clicked is perform a (push) segue to another ViewController. But the outlets in the designer aren't there for my UIControl to set up the segue.

Is it possible to do this? If so, what do I do to the class to enable that?

like image 559
ageektrapped Avatar asked Jul 24 '13 02:07

ageektrapped


People also ask

How do I add a storyboard to my segue?

To create a segue between view controllers in the same storyboard file, Control-click an appropriate element in the first view controller and drag to the target view controller. The starting point of a segue must be a view or object with a defined action, such as a control, bar button item, or gesture recognizer.

How do I get a segue identifier?

Assigning an identifier for the segue: Select the segue, from the attribute inspector you'll see "Identifier" text field, that's it! make sure to insert the exact same name that used in performSegueWithIdentifier .


1 Answers

I don't think so. Looking at the Connections Inspector pane, UIButton and UIBarButtonItem instances get special treatment—an extra "triggered segues" action you can connect to adjacent view controllers:

UIButtons can trigger segues

While changing your view's class to a descendent of UIControl makes the standard suite of control events available, unfortunately Interface Builder does not let you hook up a segue. The best you can do is create a manually-triggered segue from your view controller to another, then connect your custom control to an IBAction method that performs the segue programmatically:

- (IBAction)performManualSegue:(XYZCustomControl *)sender
{
    [self performSegueWithIdentifier:@"manualPushSegue" sender:sender];
}

IBAction for manually triggering segue

like image 146
Ryder Mackay Avatar answered Oct 20 '22 00:10

Ryder Mackay