Monal Gosai
Monal Gosai

Reputation: 23

Cannot navigate from one view controller to another with button

It gives:

signal SIGABRT

Another error in log says:

libc++abi.dylib: terminating with uncaught exception of type NSException

@IBAction func loginok(sender: AnyObject) {
    if loginTextField?.text != "monal" && passwordTextField?.text  != "gosai"
    {
        warningLable?.text = "Invalid Credentials"

        loginTextField?.text = ""
        passwordTextField?.text=""
    }
    else
    {
        let View2 = self.storyboard!.instantiateViewControllerWithIdentifier("View2") as! ViewController2
         self.navigationController!.pushViewController(View2, animated: true)

    }
}

Upvotes: 0

Views: 88

Answers (3)

Jaimy
Jaimy

Reputation: 227

In the storyboard click on the segue and in Utilities->Attributes inspector->Identifier type a name , I used "mySegue" Below the Identifier, for Segue , make it Modal.

create a button and ctrl drag to the m file: This is my code:

    - (IBAction)nAction:(UIButton *)sender {
        self.mytext =  self.mytextfield.text;
       [self performSegueWithIdentifier:@"mySegue" sender:sender];
    }



    -(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender{
        if ([[segue identifier] isEqualToString:@"mySegue"])
        {
        NSLog(@" my segues is called mysegue");
        myViewController *controller = [segue destinationViewController] ;
        controller.textforlabel = self.mytext;
        }

Don't forget to include the h file where you define the destination viewcontroller for the segue :)

Upvotes: 0

user5044932
user5044932

Reputation: 81

PerformSegueWithIdentifier won't work unless you've set up a segue in the storyboard. If you have, then in your else statement as Francisco stated you should call that function. If you have not set up the segue on the Storyboard then you will have to do so to use this method.

Also, as a matter of convention, your @IBAction method header should read func loginok(sender: UIButton) {...}

Upvotes: 2

Francisco Escobar
Francisco Escobar

Reputation: 241

You need to set a identifier to the segue and then call it with

self.performSegueWithIdentifier("YourIdentifier", sender: self)

Upvotes: 0

Related Questions