繁体   English   中英

无法使用按钮从一个视图控制器导航到另一个

[英]Cannot navigate from one view controller to another with button

它给:

信号SIGABRT

日志中的另一个错误说:

libc ++ abi.dylib:以类型为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)

    }
}

除非您在情节提要中设置了序列,否则PerformSegueWithIdentifier不会起作用。 如果有的话,那么在Francisco声明的else语句中应调用该函数。 如果尚未在情节提要板上设置序列,则必须使用此方法。

另外,根据惯例,您的@IBAction方法标头应显示为func loginok(sender: UIButton) {...}

您需要为segue设置一个标识符,然后使用

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

在情节提要中单击segue,然后在“实用工具”->“属性”检查器->“标识符”中键入一个名称,我在标识符下方使用了“ mySegue”,对于Segue,将其设置为Modal。

创建一个按钮并ctrl拖动到m文件:这是我的代码:

    - (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;
        }

不要忘记在定义segue的目标viewcontroller的位置包含h文件:)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM