How to write func..(for sequels: UIStoryboardSeque, sender: Any?) programmatically












2















I have these codes when I use storyboard:



 override func prepare (for segue: UIStoryboardSegue, sender: Any?) {

if segue.identifier == ProfilePhotoViewController.identifier {
guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

let profilePhotoVC = segue.destination as! ProfilePhotoViewController
profilePhotoVC.email = email
profilePhotoVC.username = username
profilePhotoVC.password = password
}
}


How do I write these code if I don't use storyboard and write them programmatically in order to pass the info from current controller to ProfilePhotoViewController?



EDIT:
After doing research I understand that doing this programmatically is through delegate. However, I don't know how I can complete the code:



Need to pass username, email and password from SignUpController ---> profilePhotoViewController



in SignUpController:



protocol SignUpControllerDelegate {
func handleSignUp(//what should I write here?)
}



var delegate: SignUpControllerDelegate?



@objc func handleSignUp() {



//...other code..//



delegate?.handleSignUp(//??)
}



In ProfileViewController:



what should I write to receive the username, email and password info from SignUpController?










share|improve this question





























    2















    I have these codes when I use storyboard:



     override func prepare (for segue: UIStoryboardSegue, sender: Any?) {

    if segue.identifier == ProfilePhotoViewController.identifier {
    guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

    let profilePhotoVC = segue.destination as! ProfilePhotoViewController
    profilePhotoVC.email = email
    profilePhotoVC.username = username
    profilePhotoVC.password = password
    }
    }


    How do I write these code if I don't use storyboard and write them programmatically in order to pass the info from current controller to ProfilePhotoViewController?



    EDIT:
    After doing research I understand that doing this programmatically is through delegate. However, I don't know how I can complete the code:



    Need to pass username, email and password from SignUpController ---> profilePhotoViewController



    in SignUpController:



    protocol SignUpControllerDelegate {
    func handleSignUp(//what should I write here?)
    }



    var delegate: SignUpControllerDelegate?



    @objc func handleSignUp() {



    //...other code..//



    delegate?.handleSignUp(//??)
    }



    In ProfileViewController:



    what should I write to receive the username, email and password info from SignUpController?










    share|improve this question



























      2












      2








      2








      I have these codes when I use storyboard:



       override func prepare (for segue: UIStoryboardSegue, sender: Any?) {

      if segue.identifier == ProfilePhotoViewController.identifier {
      guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

      let profilePhotoVC = segue.destination as! ProfilePhotoViewController
      profilePhotoVC.email = email
      profilePhotoVC.username = username
      profilePhotoVC.password = password
      }
      }


      How do I write these code if I don't use storyboard and write them programmatically in order to pass the info from current controller to ProfilePhotoViewController?



      EDIT:
      After doing research I understand that doing this programmatically is through delegate. However, I don't know how I can complete the code:



      Need to pass username, email and password from SignUpController ---> profilePhotoViewController



      in SignUpController:



      protocol SignUpControllerDelegate {
      func handleSignUp(//what should I write here?)
      }



      var delegate: SignUpControllerDelegate?



      @objc func handleSignUp() {



      //...other code..//



      delegate?.handleSignUp(//??)
      }



      In ProfileViewController:



      what should I write to receive the username, email and password info from SignUpController?










      share|improve this question
















      I have these codes when I use storyboard:



       override func prepare (for segue: UIStoryboardSegue, sender: Any?) {

      if segue.identifier == ProfilePhotoViewController.identifier {
      guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

      let profilePhotoVC = segue.destination as! ProfilePhotoViewController
      profilePhotoVC.email = email
      profilePhotoVC.username = username
      profilePhotoVC.password = password
      }
      }


      How do I write these code if I don't use storyboard and write them programmatically in order to pass the info from current controller to ProfilePhotoViewController?



      EDIT:
      After doing research I understand that doing this programmatically is through delegate. However, I don't know how I can complete the code:



      Need to pass username, email and password from SignUpController ---> profilePhotoViewController



      in SignUpController:



      protocol SignUpControllerDelegate {
      func handleSignUp(//what should I write here?)
      }



      var delegate: SignUpControllerDelegate?



      @objc func handleSignUp() {



      //...other code..//



      delegate?.handleSignUp(//??)
      }



      In ProfileViewController:



      what should I write to receive the username, email and password info from SignUpController?







      swift segue programmatically






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 24 '18 at 2:25







      富源Verve

















      asked Nov 23 '18 at 4:53









      富源Verve富源Verve

      2917




      2917
























          2 Answers
          2






          active

          oldest

          votes


















          -1














          Try like this



          guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

          let profileVC = ProfilePhotoViewController()
          profileVC.email = email





          share|improve this answer
























          • It is simpler than I thought. Thanks.

            – 富源Verve
            Nov 26 '18 at 2:10



















          2














          We can create a view controller with/without a NIB file.



          With NIB, you use init(nibName: String?, bundle: Bundle?) method. In this case, view will be defined using Interface Builder.



          // bundle = nil denote the main bundle
          let viewController = MyViewController(nibName:"MyViewController", bundle: nil)


          Also you can define a custom UIViewController subclass without a NIB file and implement loadView() method.



          override func loadView() {
          self.view = UIView(...)
          }


          After that, we need to add the view into the view hierarchy.



          self.view.addSubview(viewController.view);
          // or
          self.present(viewController, animated: false, completion: nil)
          // or if we have UINavigationController
          self.navigationController?.pushViewController(viewController, animated: false)





          share|improve this answer
























          • Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

            – 富源Verve
            Nov 24 '18 at 2:05











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440820%2fhow-to-write-func-for-sequels-uistoryboardseque-sender-any-programmatical%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          -1














          Try like this



          guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

          let profileVC = ProfilePhotoViewController()
          profileVC.email = email





          share|improve this answer
























          • It is simpler than I thought. Thanks.

            – 富源Verve
            Nov 26 '18 at 2:10
















          -1














          Try like this



          guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

          let profileVC = ProfilePhotoViewController()
          profileVC.email = email





          share|improve this answer
























          • It is simpler than I thought. Thanks.

            – 富源Verve
            Nov 26 '18 at 2:10














          -1












          -1








          -1







          Try like this



          guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

          let profileVC = ProfilePhotoViewController()
          profileVC.email = email





          share|improve this answer













          Try like this



          guard let username = usernameTextField.text, let email = emailTextField.text, let password = passwordTextField.text else { return }

          let profileVC = ProfilePhotoViewController()
          profileVC.email = email






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 4:58









          ktr kathirktr kathir

          920726




          920726













          • It is simpler than I thought. Thanks.

            – 富源Verve
            Nov 26 '18 at 2:10



















          • It is simpler than I thought. Thanks.

            – 富源Verve
            Nov 26 '18 at 2:10

















          It is simpler than I thought. Thanks.

          – 富源Verve
          Nov 26 '18 at 2:10





          It is simpler than I thought. Thanks.

          – 富源Verve
          Nov 26 '18 at 2:10













          2














          We can create a view controller with/without a NIB file.



          With NIB, you use init(nibName: String?, bundle: Bundle?) method. In this case, view will be defined using Interface Builder.



          // bundle = nil denote the main bundle
          let viewController = MyViewController(nibName:"MyViewController", bundle: nil)


          Also you can define a custom UIViewController subclass without a NIB file and implement loadView() method.



          override func loadView() {
          self.view = UIView(...)
          }


          After that, we need to add the view into the view hierarchy.



          self.view.addSubview(viewController.view);
          // or
          self.present(viewController, animated: false, completion: nil)
          // or if we have UINavigationController
          self.navigationController?.pushViewController(viewController, animated: false)





          share|improve this answer
























          • Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

            – 富源Verve
            Nov 24 '18 at 2:05
















          2














          We can create a view controller with/without a NIB file.



          With NIB, you use init(nibName: String?, bundle: Bundle?) method. In this case, view will be defined using Interface Builder.



          // bundle = nil denote the main bundle
          let viewController = MyViewController(nibName:"MyViewController", bundle: nil)


          Also you can define a custom UIViewController subclass without a NIB file and implement loadView() method.



          override func loadView() {
          self.view = UIView(...)
          }


          After that, we need to add the view into the view hierarchy.



          self.view.addSubview(viewController.view);
          // or
          self.present(viewController, animated: false, completion: nil)
          // or if we have UINavigationController
          self.navigationController?.pushViewController(viewController, animated: false)





          share|improve this answer
























          • Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

            – 富源Verve
            Nov 24 '18 at 2:05














          2












          2








          2







          We can create a view controller with/without a NIB file.



          With NIB, you use init(nibName: String?, bundle: Bundle?) method. In this case, view will be defined using Interface Builder.



          // bundle = nil denote the main bundle
          let viewController = MyViewController(nibName:"MyViewController", bundle: nil)


          Also you can define a custom UIViewController subclass without a NIB file and implement loadView() method.



          override func loadView() {
          self.view = UIView(...)
          }


          After that, we need to add the view into the view hierarchy.



          self.view.addSubview(viewController.view);
          // or
          self.present(viewController, animated: false, completion: nil)
          // or if we have UINavigationController
          self.navigationController?.pushViewController(viewController, animated: false)





          share|improve this answer













          We can create a view controller with/without a NIB file.



          With NIB, you use init(nibName: String?, bundle: Bundle?) method. In this case, view will be defined using Interface Builder.



          // bundle = nil denote the main bundle
          let viewController = MyViewController(nibName:"MyViewController", bundle: nil)


          Also you can define a custom UIViewController subclass without a NIB file and implement loadView() method.



          override func loadView() {
          self.view = UIView(...)
          }


          After that, we need to add the view into the view hierarchy.



          self.view.addSubview(viewController.view);
          // or
          self.present(viewController, animated: false, completion: nil)
          // or if we have UINavigationController
          self.navigationController?.pushViewController(viewController, animated: false)






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 23 '18 at 5:33









          9dan9dan

          3,55322340




          3,55322340













          • Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

            – 富源Verve
            Nov 24 '18 at 2:05



















          • Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

            – 富源Verve
            Nov 24 '18 at 2:05

















          Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

          – 富源Verve
          Nov 24 '18 at 2:05





          Thanks for the input, after doing some research, I found out that doing programmatically is to through delegate method. Do you know how to do that? I don't want to use storyboard and nib, I want to do it programmatically.

          – 富源Verve
          Nov 24 '18 at 2:05


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53440820%2fhow-to-write-func-for-sequels-uistoryboardseque-sender-any-programmatical%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          RAC Tourist Trophy