0

Normally (when using XCode storyboard to create an UI) ctrl-drag does the job of creating a segue to an other view controller. Works perfect with an UIButton.

But how to create a segue with ctrl-drag if the UIButton is located inside a custom view (subclass of UIView that is) ?

import UIKit

// class KachelView is used several times in 
// the main storyboard on entry panel.

@IBDesignable
class KachelView: UIView {
// normal stuff here
// XIB file contains a UIButton that is 
// to ignite a segue in the outer view
}

Is there a way to do this inside the storyboard or am I to do it in code?

karldegen
  • 113
  • 8
  • 1
    Can't you ctrl-drag from your desired button in storyboard? –  Apr 24 '17 at 08:37
  • The UIButton is part of the custom UIView. This seems to prevent using it as normal UIButton with ctrl-drag stuff. Does not work – karldegen Apr 24 '17 at 22:15
  • Solved problem using the answer from @Edgar plus some additional ado. I subclassed from UIControl instead of UIView. So I could use the notifier/observer-mechanism of UIKit to create an event inside KachelView that could be subscribed in the storyboard class. Then segue by code. – karldegen May 09 '17 at 16:37

1 Answers1

0

Unfortunately, it does not seem to be possible to create a Segue via Interface Builder from a Designable View. Think of a Designable View just as a way to render the view within the Interface Builder so that it looks more like what you get on the simulator or a real device.

In alternative, create an IBAction on your custom view (KachelView) and delegate back to the view controller who owns it (set the view controller as delegate when setting up the view). Then you can easily perform a segue programatically using:

performSegue(withIdentifier: <YOUR_IDENTIFIER>, sender: self)
Edgar
  • 2,500
  • 19
  • 31