1

I am using swift 4

I have a tab bar controller where I created a programmatically button in the middle of the tab bar. Upon button click I want to perform segue and show the next view. I created the segue from the tabar view to the next view and named it moveToNext.

here is the button

let button = UIButton.init(type: .custom)

override func viewDidLoad() {
    super.viewDidLoad()


    let blue = UIColor(red: 53/255, green: 92/255, blue: 125/255, alpha: 1.0)

    UITabBar.appearance().tintColor = blue

    button.setTitle("+", for: .normal)
    button.titleLabel?.font = .systemFont(ofSize: 32)
    button.setTitleColor(.white, for: .normal)
    button.setTitleColor(.white, for: .highlighted)

    button.backgroundColor = blue
    button.layer.cornerRadius = 32
    button.layer.borderWidth = 1.5
    button.layer.borderColor = blue.cgColor
    //button.layer.borderColor = UIColor.green.cgColor


    button.addTarget(self, action:#selector(self.buttonClicked), for: .touchUpInside)

    self.view.insertSubview(button, aboveSubview: self.tabBar)

    UITabBar.appearance().backgroundImage = UIImage.colorForNavBar(color: .white)
    UITabBar.appearance().shadowImage = UIImage.colorForNavBar(color: blue)

}


@objc func buttonClicked() {
    print("Button Clicked")
    self.performSegue(withIdentifier: "moveToNext", sender: self)

}

I get the following error

'Receiver (<Pac.CustomTabBarViewController: 0x7fc94285be00>) has no segue with identifier 'moveToNext''
*** First throw call stack:

Im fairly new to swift and Xcode, and come from java background.

enter image description here

I think I am performing the segue correctly. Why can't it find the segue and how can I fire it from the button click?

Thanks for taking the time to read this and help me.

steller
  • 245
  • 3
  • 14

1 Answers1

1
  • Have you established the segue? In IB ⌃-drag from the the source controller (yellow icon) to the destination view controller)?
  • Have you specified the identifier? Select the segue, press ⌥⌘4 and type moveToNext in the Identifier field.
vadian
  • 274,689
  • 30
  • 353
  • 361
  • Yes, I have done that. I thought I specified that in my post. Thats the reason why I am posting as I have done everything right. – steller Oct 20 '18 at 05:46
  • There are a few ways to do that but making mistakes anyhow (for example wrong source object of the segue) – vadian Oct 20 '18 at 05:48
  • I got it. There are like 4 tabor controls. I was using the wrong one – steller Oct 20 '18 at 20:12