2

In my App after signup/login I want to move control to specific tab of UITabBarController on some conditions. My login or Signup Pages are not in UITabBarController.
Here is the code of my login button I have tried but it only works with identifier or UITabBarController. In my case I want to move to specific tab like 2nd or 3rd tab.

@IBAction func btn_login(sender: AnyObject) {
        activityIndicator.progressBarDisplayer("Logging In", true, uiView: self.view)
        let timezone = GLib.timezone();
        let parameters = ["email": txtemail.text!,"password": txtpassword.text!,"time_zone": timezone]
        GLib.fetch("www.abc.com/test/auth/login", parameters: parameters, localkey: "user"){
            (isResponse) -> Void in
            if(isResponse == true)
            {
                self.activityIndicator.strLabel.text = "Personalizing Data";

                let viewController:UIViewController = UIStoryboard(name: "Main", bundle: nil).instantiateViewControllerWithIdentifier("some identifier") as UIViewController;
                self.presentViewController(viewController, animated: false, completion: nil);

              }else
              {
                self.show_alert("Attention Please!", message: self.GLib.error)
            }
}

I have seen many posts but found nothing similar to my mechanism.

I am new to iOS programming so don't know how to figure out this issue.

perror
  • 7,071
  • 16
  • 58
  • 85
Haseeb
  • 2,214
  • 1
  • 22
  • 43
  • I don't understand what you're trying to do. When the user signs in you want to move to a specific viewController. Right? – Lukesivi Dec 05 '15 at 09:56
  • @lukesIvi after singup i want to move user to 2nd tab of UITabBarController – Haseeb Dec 05 '15 at 09:58
  • 1
    I'm assuming the 2nd viewController will always be the same VC. Your 2nd tab in the UITabBarController is a VC either way, so just give it an ID and then access it like that. I can write the answer if you need further help. – Lukesivi Dec 05 '15 at 10:00
  • @lukeslvi can you please give me the code – Haseeb Dec 05 '15 at 10:06

1 Answers1

1

Using instantiateViewControllerWithIdentifier is the right way to go. However, you need to add the actual identifier, and the UIViewController Custom class type needs to be the actual class.

I'm going to give you a rough example of what it looks like, but it should work. Either way you have to edit your instantiate method as I explain below.

Steps:

Firstly, set the "Storyboard ID" for the viewController in your storyboard. Like this:

enter image description here

Then add this code modified instantiateViewControllerWithIdentifier method:

   @IBAction func btn_login(sender: AnyObject) {
        activityIndicator.progressBarDisplayer("Logging In", true, uiView: self.view)
        let timezone = GLib.timezone();
        let parameters = ["email": txtemail.text!,"password": txtpassword.text!,"time_zone": timezone]
        GLib.fetch("www.abc.com/test/auth/login", parameters: parameters, localkey: "user"){
            (isResponse) -> Void in
            if(isResponse == true)
            {
                self.activityIndicator.strLabel.text = "Personalizing Data";


                let yourNewViewController: ViewControllerClassName = self.storyboard!.instantiateViewControllerWithIdentifier("yourStoryBoardID") as! ViewControllerYourePushingTo


                self.presentViewController(yourNewViewController, animated: true, completion: nil)


            }else
            {
                self.show_alert("Attention Please!", message: self.GLib.error)
            }
        }

As a type, you need to actually use the viewController's name.

I asked a similar question a few weeks ago: Swift: Triggering TableViewCell to lead to a link in a UIWebView in another ViewController

Community
  • 1
  • 1
Lukesivi
  • 2,206
  • 4
  • 25
  • 43