0

Im a beginner in swift and I am creating a login screen using Material.io in Swift and my UI looks like this ui. However i dont see anything on my main.storyboard main.storyboard I am used to creating a segue manually and then using

performSegue(withIdentifier: <#T##String#>, sender: <#T##Any?#>)
to use the segue but now since i dont see the button i'm unable to use the segue on clicking the 2 buttons Login and Register.

Also, usually from main.storyboard you have an IBOutlet or IBAction block to trigger certain features such as do something on a button click. How does that work when you use MDCButton for instance. How do you link up the button to an action such as trigger a segue or update a text field. Thank you.

I have declared my button like this

 let nextButton: MDCButton = {
        let nextButton = MDCButton()
        let containerScheme = MDCContainerScheme()
        nextButton.applyTextTheme(withScheme: containerScheme)
        nextButton.setTitleColor(.white, for: .normal)
        nextButton.translatesAutoresizingMaskIntoConstraints = false
        nextButton.setTitle("CREATE NEW ACCOUNT", for: .normal)
        nextButton.addTarget(self, action: #selector(didTapNext(sender:)), for: .touchUpInside)
        return nextButton
    }()

And i am calling it like this

 @objc func didTapNext(sender: Any) {
        self.performSegue(withIdentifier: "toRegistration", sender: self)
        self.dismiss(animated: true, completion: nil)
    }

I have a segue linking the 2 view controllers.

Community
  • 1
  • 1

1 Answers1

0

I can't see your code and don't have enough rep to comment, but it looks like you are building your view programmatically. To see when the button receives touchUp as you would from an outlet, you need to add a target. Try something like this:

func functionWhereYouCreateTheButton() { (PROBABLY YOUR VIEW DID LOAD)
   let loginButton = UIButton()...
   ...
   ...
   ...
   loginButton.addTarget(self, action: #selector(self.buttonTapped), for: .touchUpInside)
}

func buttonTapped() {
   self.performSegue(withIdentifier: "SEGUEID", sender: self)
}
blorsch
  • 70
  • 1
  • 9
  • i updated the description above and i feel i am doing as you have mentioned. Could you please have a look. Thank you – mridul ghanshala Jun 11 '19 at 01:11
  • @mridulghanshala I think calling `dismiss` is causing the issues. Have you tried it without that? Also have you tried adding a `print` statement in `didTapNext` to see if the button is calling that function? – blorsch Jun 12 '19 at 18:00
  • do u think if i created 1 view manually and 1 from storyboard and link the 2 up through a segue i am going the right way or i should do something like performnavigation – mridul ghanshala Jun 12 '19 at 18:29
  • I'm don't understand. What view is manual and which is storyboard? – blorsch Jun 14 '19 at 04:06