Segue IOS does not work

0

How about, I'm new to swift 3, I'm developing an app using cocoapods, to be more specific SwipeViewController 0.1.8 library and when I want to use a segue to change my scene, I get the following error:

  

Terminating app due to uncaught exception   'NSInvalidArgumentException', reason: 'Receiver () has not segue with identifier' segue_1 ''

My segue if it has the identifier "segue_1" as defined in the error, however my main ViewController is not subclass% of UIViewController , but "SwipeViewController", which I guess is what generates me the exception, I leave my code.

import UIKit
import SwipeViewController

class ViewController: SwipeViewController{
    override func viewDidLoad() {
        super.viewDidLoad()
        //Uso de SwipeViewController Cocoapods
        let stb = UIStoryboard(name: "Main", bundle: nil)
        let page_one   = stb.instantiateViewController(withIdentifier: "page1") as UIViewController
        let page_two   = stb.instantiateViewController(withIdentifier: "page2") as UIViewController
        let page_three = stb.instantiateViewController(withIdentifier: "page3") as UIViewController
        let page_four  = stb.instantiateViewController(withIdentifier: "page4") as UIViewController
        let page_five  = stb.instantiateViewController(withIdentifier: "page5") as UIViewController
        let page_six   = stb.instantiateViewController(withIdentifier: "page6") as UIViewController

        setViewControllerArray([page_one, page_two, page_three, page_four, page_five, page_six])
        setFirstViewController(0)
        setNavigationBarHidden(true, animated: false)

        //Uso de SwipeViewController Cocoapods
        //Creación de botones
        let btnNew = UIButton(frame: CGRect(x: self.view.frame.size.width / 2 + 30, y: self.view.frame.size.height - 75, width: self.view.frame.size.width / 2 - 35, height: 50))
        btnNew.setTitle("SOY NUEVO", for: .normal)
        btnNew.addTarget(self, action: #selector(soyNuevo), for: .touchUpInside)
        btnNew.layer.cornerRadius = 25.0
        btnNew.layer.masksToBounds = true
        btnNew.backgroundColor = getColorByHex(rgbHexValue: 0x0071bc, alpha: 1.0)
        btnNew.titleLabel!.font = UIFont(name: "OpenSans-Semibold", size: 13)
        self.view.addSubview(btnNew)

        let btnCta = UIButton(frame: CGRect(x: self.view.frame.size.width - self.view.frame.size.width + 10, y: self.view.frame.size.height - 75, width: self.view.frame.size.width/2-35, height: 50))
        btnCta.setTitle("YA TENGO CUENTA", for: .normal)
        btnCta.addTarget(self, action: #selector(tengoCuenta), for: .touchUpInside)
        btnCta.layer.cornerRadius = 25.0
        btnCta.layer.masksToBounds = true
        btnCta.backgroundColor = getColorByHex(rgbHexValue: 0xff5004, alpha: 1.0)
        btnCta.titleLabel?.font = UIFont(name: "OpenSans-Semibold", size: 13)
        self.view.addSubview(btnCta)
        //Creación de botones
    }

    func soyNuevo(sender: UIButton){
        print("Soy Nuevo")
        performSegue(withIdentifier: "segue_1", sender: self)
    }
    func tengoCuenta(sender: UIButton){
        print("Ya Tengo Cuenta")
    }

    func getColorByHex(rgbHexValue:UInt32, alpha:Double = 1.0) -> UIColor {
        let red   = Double((rgbHexValue & 0xFF0000) >> 16) / 256.0
        let green = Double((rgbHexValue & 0xFF00) >> 8) / 256.0
        let blue  = Double((rgbHexValue & 0xFF)) / 256.0

        return UIColor(red: CGFloat(red), green: CGFloat(green), blue: CGFloat(blue), alpha: CGFloat(alpha))
    }

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
}
    
asked by Sergio García 26.07.2017 в 00:52
source

2 answers

1

Thank you very much for the support, it was already resolved as follows:

func soyNuevo(sender: UIButton){
    let registro1 = stb.instantiateViewController(withIdentifier: "registro_1") as! Registro1
    self.present(registro1, animated: true, completion: nil)
}

The class "Registry1" was created, to which the viewController was assigned. I appreciate the support and attention!

    
answered by 26.07.2017 / 17:23
source
0

If you are sure that the identifier of the segue is correct but it still does not work, you can open the new view with code. Replace the "performSegure" line with

        let ventana = stb.instantiateViewController(withIdentifier: "storyboardID") as UIViewController
        self.navigationController?.pushViewController(ventana, animated: false)

edited There are several ways to present a viewController by code and you can use the one that fits what you need

    
answered by 26.07.2017 в 08:31